blob: 93a87806b0d5d8854887e404aa3d3314eb9827c2 [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 %
16% John Cristy %
17% July 1992 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 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"
43#include "MagickCore/blob.h"
44#include "MagickCore/blob-private.h"
45#include "MagickCore/constitute.h"
46#include "MagickCore/exception.h"
47#include "MagickCore/exception-private.h"
48#include "MagickCore/magick.h"
49#include "MagickCore/memory_.h"
50#include "MagickCore/monitor.h"
51#include "MagickCore/monitor-private.h"
52#include "MagickCore/quantum-private.h"
53#include "MagickCore/static.h"
54#include "MagickCore/string_.h"
55#include "MagickCore/module.h"
cristy3ed852e2009-09-05 21:47:34 +000056
57/*
58 Forward declarations.
59*/
60static MagickBooleanType
61 WriteCLIPImage(const ImageInfo *,Image *);
62
63/*
64%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65% %
66% %
67% %
68% R e g i s t e r C L I P I m a g e %
69% %
70% %
71% %
72%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73%
74% RegisterCLIPImage() adds attributes for the CLIP image format to
75% the list of supported formats. The attributes include the image format
76% tag, a method to read and/or write the format, whether the format
77% supports the saving of more than one frame to the same file or blob,
78% whether the format supports native in-memory I/O, and a brief
79% description of the format.
80%
81% The format of the RegisterCLIPImage method is:
82%
cristybb503372010-05-27 20:51:26 +000083% size_t RegisterCLIPImage(void)
cristy3ed852e2009-09-05 21:47:34 +000084%
85*/
cristybb503372010-05-27 20:51:26 +000086ModuleExport size_t RegisterCLIPImage(void)
cristy3ed852e2009-09-05 21:47:34 +000087{
88 MagickInfo
89 *entry;
90
91 entry=SetMagickInfo("CLIP");
92 entry->encoder=(EncodeImageHandler *) WriteCLIPImage;
93 entry->description=ConstantString("Image Clip Mask");
94 entry->module=ConstantString("CLIP");
95 (void) RegisterMagickInfo(entry);
96 return(MagickImageCoderSignature);
97}
98
99/*
100%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101% %
102% %
103% %
104% U n r e g i s t e r C L I P I m a g e %
105% %
106% %
107% %
108%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109%
110% UnregisterCLIPImage() removes format registrations made by the
111% CLIP module from the list of supported formats.
112%
113% The format of the UnregisterCLIPImage method is:
114%
115% UnregisterCLIPImage(void)
116%
117*/
118ModuleExport void UnregisterCLIPImage(void)
119{
120 (void) UnregisterMagickInfo("CLIP");
121}
122
123/*
124%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125% %
126% %
127% %
128% W r i t e C L I P I m a g e %
129% %
130% %
131% %
132%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133%
134% WriteCLIPImage() writes an image of clip bytes to a file. It consists of
135% data from the clip mask of the image.
136%
137% The format of the WriteCLIPImage method is:
138%
139% MagickBooleanType WriteCLIPImage(const ImageInfo *image_info,
140% Image *image)
141%
142% A description of each parameter follows.
143%
144% o image_info: the image info.
145%
146% o image: The image.
147%
148*/
149static MagickBooleanType WriteCLIPImage(const ImageInfo *image_info,
150 Image *image)
151{
152 Image
153 *clip_image;
154
155 ImageInfo
156 *write_info;
157
158 MagickBooleanType
159 status;
160
161 if (image->clip_mask == (Image *) NULL)
162 (void) ClipImage(image);
163 if (image->clip_mask == (Image *) NULL)
164 ThrowWriterException(CoderError,"ImageDoesNotHaveAClipMask");
165 clip_image=CloneImage(image->clip_mask,0,0,MagickTrue,&image->exception);
166 if (clip_image == (Image *) NULL)
167 return(MagickFalse);
168 (void) SetImageType(clip_image,TrueColorType);
169 (void) CopyMagickString(clip_image->filename,image->filename,MaxTextExtent);
170 write_info=CloneImageInfo(image_info);
cristyd965a422010-03-03 17:47:35 +0000171 (void) SetImageInfo(write_info,1,&image->exception);
cristy3ed852e2009-09-05 21:47:34 +0000172 if (LocaleCompare(write_info->magick,"CLIP") == 0)
cristyb51dff52011-05-19 16:55:47 +0000173 (void) FormatLocaleString(clip_image->filename,MaxTextExtent,"miff:%s",
cristy3ed852e2009-09-05 21:47:34 +0000174 write_info->filename);
175 status=WriteImage(write_info,clip_image);
176 clip_image=DestroyImage(clip_image);
177 write_info=DestroyImageInfo(write_info);
178 return(status);
179}