blob: 36ae9aa6cb9c5e2310e819e8453653252b4ffa26 [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% %
cristy45ef08f2012-12-07 13:13:34 +000020% Copyright 1999-2013 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"
49#include "MagickCore/magick.h"
50#include "MagickCore/memory_.h"
51#include "MagickCore/monitor.h"
52#include "MagickCore/monitor-private.h"
53#include "MagickCore/quantum-private.h"
54#include "MagickCore/static.h"
55#include "MagickCore/string_.h"
56#include "MagickCore/module.h"
cristy3ed852e2009-09-05 21:47:34 +000057
58/*
59 Forward declarations.
60*/
61static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +000062 WriteCLIPImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +000063
64/*
65%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66% %
67% %
68% %
69% R e g i s t e r C L I P I m a g e %
70% %
71% %
72% %
73%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74%
75% RegisterCLIPImage() adds attributes for the CLIP image format to
76% the list of supported formats. The attributes include the image format
77% tag, a method to read and/or write the format, whether the format
78% supports the saving of more than one frame to the same file or blob,
79% whether the format supports native in-memory I/O, and a brief
80% description of the format.
81%
82% The format of the RegisterCLIPImage method is:
83%
cristybb503372010-05-27 20:51:26 +000084% size_t RegisterCLIPImage(void)
cristy3ed852e2009-09-05 21:47:34 +000085%
86*/
cristybb503372010-05-27 20:51:26 +000087ModuleExport size_t RegisterCLIPImage(void)
cristy3ed852e2009-09-05 21:47:34 +000088{
89 MagickInfo
90 *entry;
91
92 entry=SetMagickInfo("CLIP");
93 entry->encoder=(EncodeImageHandler *) WriteCLIPImage;
94 entry->description=ConstantString("Image Clip Mask");
95 entry->module=ConstantString("CLIP");
96 (void) RegisterMagickInfo(entry);
97 return(MagickImageCoderSignature);
98}
99
100/*
101%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102% %
103% %
104% %
105% U n r e g i s t e r C L I P I m a g e %
106% %
107% %
108% %
109%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110%
111% UnregisterCLIPImage() removes format registrations made by the
112% CLIP module from the list of supported formats.
113%
114% The format of the UnregisterCLIPImage method is:
115%
116% UnregisterCLIPImage(void)
117%
118*/
119ModuleExport void UnregisterCLIPImage(void)
120{
121 (void) UnregisterMagickInfo("CLIP");
122}
123
124/*
125%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126% %
127% %
128% %
129% W r i t e C L I P I m a g e %
130% %
131% %
132% %
133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134%
135% WriteCLIPImage() writes an image of clip bytes to a file. It consists of
136% data from the clip mask of the image.
137%
138% The format of the WriteCLIPImage method is:
139%
140% MagickBooleanType WriteCLIPImage(const ImageInfo *image_info,
cristy1e178e72011-08-28 19:44:34 +0000141% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000142%
143% A description of each parameter follows.
144%
145% o image_info: the image info.
146%
147% o image: The image.
148%
cristy1e178e72011-08-28 19:44:34 +0000149% o exception: return any errors or warnings in this structure.
150%
cristy3ed852e2009-09-05 21:47:34 +0000151*/
152static MagickBooleanType WriteCLIPImage(const ImageInfo *image_info,
cristy1e178e72011-08-28 19:44:34 +0000153 Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000154{
155 Image
156 *clip_image;
157
158 ImageInfo
159 *write_info;
160
161 MagickBooleanType
162 status;
163
cristy183a5c72012-01-30 01:40:35 +0000164 if (image->mask == MagickFalse)
cristy018f07f2011-09-04 21:15:19 +0000165 (void) ClipImage(image,exception);
cristy183a5c72012-01-30 01:40:35 +0000166 if (image->mask == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000167 ThrowWriterException(CoderError,"ImageDoesNotHaveAClipMask");
cristy10a6c612012-01-29 21:41:05 +0000168 clip_image=GetImageMask(image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000169 if (clip_image == (Image *) NULL)
170 return(MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +0000171 (void) CopyMagickString(clip_image->filename,image->filename,MaxTextExtent);
172 write_info=CloneImageInfo(image_info);
cristy1e178e72011-08-28 19:44:34 +0000173 (void) SetImageInfo(write_info,1,exception);
cristy3ed852e2009-09-05 21:47:34 +0000174 if (LocaleCompare(write_info->magick,"CLIP") == 0)
cristyb51dff52011-05-19 16:55:47 +0000175 (void) FormatLocaleString(clip_image->filename,MaxTextExtent,"miff:%s",
cristy3ed852e2009-09-05 21:47:34 +0000176 write_info->filename);
cristy1e178e72011-08-28 19:44:34 +0000177 status=WriteImage(write_info,clip_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000178 clip_image=DestroyImage(clip_image);
179 write_info=DestroyImageInfo(write_info);
180 return(status);
181}