blob: a86823157cb0d13857c4cdb3f7ef216a52d3a27b [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% CCCC L IIIII PPPP %
7% C L I P P %
8% C L I PPPP %
9% C L I P %
10% CCCC LLLLL IIIII P %
11% %
12% %
13% Write Clip Mask To MIFF File. %
14% %
15% Software Design %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
cristyb56bb242014-11-25 17:12:48 +000020% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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*/
cristy4c08aed2011-07-01 19:47:50 +000042#include "MagickCore/studio.h"
cristy15338662012-06-21 01:45:37 +000043#include "MagickCore/attribute.h"
cristy4c08aed2011-07-01 19:47:50 +000044#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"
cristya7f89062013-03-30 21:53:44 +000049#include "MagickCore/list.h"
cristy4c08aed2011-07-01 19:47:50 +000050#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"
cristy3ed852e2009-09-05 21:47:34 +000058
59/*
60 Forward declarations.
61*/
62static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +000063 WriteCLIPImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +000064
65/*
66%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67% %
68% %
69% %
cristya7f89062013-03-30 21:53:44 +000070% R e a d C L I P I m a g e %
71% %
72% %
73% %
74%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75%
76% ReadCLIPImage returns the rendered clip path associated with the image.
77%
78% The format of the ReadCLIPImage method is:
79%
80% Image *ReadCLIPImage(const ImageInfo *image_info,
81% ExceptionInfo *exception)
82%
83% A description of each parameter follows:
84%
85% o image_info: the image info.
86%
87% o exception: return any errors or warnings in this structure.
88%
89*/
90static Image *ReadCLIPImage(const ImageInfo *image_info,
91 ExceptionInfo *exception)
92{
93 Image
94 *clip_image,
95 *image;
96
97 ImageInfo
98 *read_info;
99
100 /*
101 Initialize Image structure.
102 */
103 assert(image_info != (const ImageInfo *) NULL);
104 assert(image_info->signature == MagickSignature);
105 if (image_info->debug != MagickFalse)
106 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
107 image_info->filename);
108 assert(exception != (ExceptionInfo *) NULL);
109 assert(exception->signature == MagickSignature);
110 read_info=CloneImageInfo(image_info);
111 SetImageInfoBlob(read_info,(void *) NULL,0);
112 *read_info->magick='\0';
113 clip_image=ReadImage(read_info,exception);
114 read_info=DestroyImageInfo(read_info);
115 if (clip_image == (Image *) NULL)
116 return((Image *) NULL);
117 (void) ClipImage(clip_image,exception);
118 image=GetImageMask(clip_image,exception);
119 clip_image=DestroyImage(clip_image);
120 if (image == (Image *) NULL)
121 ThrowReaderException(CoderError,"ImageDoesNotHaveAClipMask");
122 return(GetFirstImageInList(image));
123}
124
125/*
126%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127% %
128% %
129% %
cristy3ed852e2009-09-05 21:47:34 +0000130% R e g i s t e r C L I P I m a g e %
131% %
132% %
133% %
134%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135%
136% RegisterCLIPImage() adds attributes for the CLIP image format to
137% the list of supported formats. The attributes include the image format
138% tag, a method to read and/or write the format, whether the format
139% supports the saving of more than one frame to the same file or blob,
140% whether the format supports native in-memory I/O, and a brief
141% description of the format.
142%
143% The format of the RegisterCLIPImage method is:
144%
cristybb503372010-05-27 20:51:26 +0000145% size_t RegisterCLIPImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000146%
147*/
cristybb503372010-05-27 20:51:26 +0000148ModuleExport size_t RegisterCLIPImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000149{
150 MagickInfo
151 *entry;
152
153 entry=SetMagickInfo("CLIP");
cristya7f89062013-03-30 21:53:44 +0000154 entry->decoder=(DecodeImageHandler *) ReadCLIPImage;
cristy3ed852e2009-09-05 21:47:34 +0000155 entry->encoder=(EncodeImageHandler *) WriteCLIPImage;
156 entry->description=ConstantString("Image Clip Mask");
157 entry->module=ConstantString("CLIP");
158 (void) RegisterMagickInfo(entry);
159 return(MagickImageCoderSignature);
160}
161
162/*
163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164% %
165% %
166% %
167% U n r e g i s t e r C L I P I m a g e %
168% %
169% %
170% %
171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172%
173% UnregisterCLIPImage() removes format registrations made by the
174% CLIP module from the list of supported formats.
175%
176% The format of the UnregisterCLIPImage method is:
177%
178% UnregisterCLIPImage(void)
179%
180*/
181ModuleExport void UnregisterCLIPImage(void)
182{
183 (void) UnregisterMagickInfo("CLIP");
184}
185
186/*
187%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188% %
189% %
190% %
191% W r i t e C L I P I m a g e %
192% %
193% %
194% %
195%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196%
197% WriteCLIPImage() writes an image of clip bytes to a file. It consists of
198% data from the clip mask of the image.
199%
200% The format of the WriteCLIPImage method is:
201%
202% MagickBooleanType WriteCLIPImage(const ImageInfo *image_info,
cristy1e178e72011-08-28 19:44:34 +0000203% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000204%
205% A description of each parameter follows.
206%
207% o image_info: the image info.
208%
209% o image: The image.
210%
cristy1e178e72011-08-28 19:44:34 +0000211% o exception: return any errors or warnings in this structure.
212%
cristy3ed852e2009-09-05 21:47:34 +0000213*/
214static MagickBooleanType WriteCLIPImage(const ImageInfo *image_info,
cristy1e178e72011-08-28 19:44:34 +0000215 Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000216{
217 Image
218 *clip_image;
219
220 ImageInfo
221 *write_info;
222
223 MagickBooleanType
224 status;
225
cristy883fde12013-04-08 00:50:13 +0000226 if (image->read_mask == MagickFalse)
cristy018f07f2011-09-04 21:15:19 +0000227 (void) ClipImage(image,exception);
cristy883fde12013-04-08 00:50:13 +0000228 if (image->read_mask == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000229 ThrowWriterException(CoderError,"ImageDoesNotHaveAClipMask");
cristy10a6c612012-01-29 21:41:05 +0000230 clip_image=GetImageMask(image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000231 if (clip_image == (Image *) NULL)
232 return(MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +0000233 (void) CopyMagickString(clip_image->filename,image->filename,MaxTextExtent);
234 write_info=CloneImageInfo(image_info);
cristy1e178e72011-08-28 19:44:34 +0000235 (void) SetImageInfo(write_info,1,exception);
cristy3ed852e2009-09-05 21:47:34 +0000236 if (LocaleCompare(write_info->magick,"CLIP") == 0)
cristyb51dff52011-05-19 16:55:47 +0000237 (void) FormatLocaleString(clip_image->filename,MaxTextExtent,"miff:%s",
cristy3ed852e2009-09-05 21:47:34 +0000238 write_info->filename);
cristy1e178e72011-08-28 19:44:34 +0000239 status=WriteImage(write_info,clip_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000240 clip_image=DestroyImage(clip_image);
241 write_info=DestroyImageInfo(write_info);
242 return(status);
243}