2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % M M AAA TTTTT TTTTT EEEEE %
8 % M M M AAAAA T T EEE %
13 % Write Matte Channel To MIFF File. %
20 % Copyright 1999-2011 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 "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/cache.h"
46 #include "magick/constitute.h"
47 #include "magick/exception.h"
48 #include "magick/exception-private.h"
49 #include "magick/image-private.h"
50 #include "magick/list.h"
51 #include "magick/magick.h"
52 #include "magick/memory_.h"
53 #include "magick/monitor.h"
54 #include "magick/monitor-private.h"
55 #include "magick/quantum-private.h"
56 #include "magick/static.h"
57 #include "magick/string_.h"
58 #include "magick/module.h"
63 static MagickBooleanType
64 WriteMATTEImage(const ImageInfo *,Image *);
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 % R e g i s t e r M A T T E I m a g e %
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 % RegisterMATTEImage() adds attributes for the MATTE image format to
78 % the list of supported formats. The attributes include the image format
79 % tag, a method to read and/or write the format, whether the format
80 % supports the saving of more than one frame to the same file or blob,
81 % whether the format supports native in-memory I/O, and a brief
82 % description of the format.
84 % The format of the RegisterMATTEImage method is:
86 % size_t RegisterMATTEImage(void)
89 ModuleExport size_t RegisterMATTEImage(void)
94 entry=SetMagickInfo("MATTE");
95 entry->encoder=(EncodeImageHandler *) WriteMATTEImage;
96 entry->format_type=ExplicitFormatType;
97 entry->description=ConstantString("MATTE format");
98 entry->module=ConstantString("MATTE");
99 (void) RegisterMagickInfo(entry);
100 return(MagickImageCoderSignature);
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 % U n r e g i s t e r M A T T E I m a g e %
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 % UnregisterMATTEImage() removes format registrations made by the
115 % MATTE module from the list of supported formats.
117 % The format of the UnregisterMATTEImage method is:
119 % UnregisterMATTEImage(void)
122 ModuleExport void UnregisterMATTEImage(void)
124 (void) UnregisterMagickInfo("MATTE");
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 % W r i t e M A T T E I m a g e %
136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138 % Function WriteMATTEImage() writes an image of matte bytes to a file. It
139 % consists of data from the matte component of the image [0..255].
141 % The format of the WriteMATTEImage method is:
143 % MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
146 % A description of each parameter follows.
148 % o image_info: the image info.
150 % o image: The image.
153 static MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
165 register const PixelPacket
177 if (image->matte == MagickFalse)
178 ThrowWriterException(CoderError,"ImageDoesNotHaveAAlphaChannel");
179 matte_image=CloneImage(image,image->columns,image->rows,MagickTrue,
181 if (matte_image == (Image *) NULL)
183 (void) SetImageType(matte_image,TrueColorMatteType);
184 matte_image->matte=MagickFalse;
186 Convert image to matte pixels.
188 exception=(&image->exception);
189 for (y=0; y < (ssize_t) image->rows; y++)
191 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
192 q=QueueAuthenticPixels(matte_image,0,y,matte_image->columns,1,exception);
193 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
195 for (x=0; x < (ssize_t) image->columns; x++)
197 SetRedPixelComponent(q,GetOpacityPixelComponent(p));
198 SetGreenPixelComponent(q,GetOpacityPixelComponent(p));
199 SetBluePixelComponent(q,GetOpacityPixelComponent(p));
200 SetOpacityPixelComponent(q,OpaqueOpacity);
204 if (SyncAuthenticPixels(matte_image,exception) == MagickFalse)
206 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
208 if (status == MagickFalse)
211 (void) FormatLocaleString(matte_image->filename,MaxTextExtent,
212 "MIFF:%s",image->filename);
213 status=WriteImage(image_info,matte_image);
214 matte_image=DestroyImage(matte_image);