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 "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/constitute.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/image-private.h"
50 #include "MagickCore/list.h"
51 #include "MagickCore/magick.h"
52 #include "MagickCore/memory_.h"
53 #include "MagickCore/monitor.h"
54 #include "MagickCore/monitor-private.h"
55 #include "MagickCore/pixel-accessor.h"
56 #include "MagickCore/quantum-private.h"
57 #include "MagickCore/static.h"
58 #include "MagickCore/string_.h"
59 #include "MagickCore/module.h"
64 static MagickBooleanType
65 WriteMATTEImage(const ImageInfo *,Image *,ExceptionInfo *);
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 % R e g i s t e r M A T T E I m a g e %
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 % RegisterMATTEImage() adds attributes for the MATTE image format to
79 % the list of supported formats. The attributes include the image format
80 % tag, a method to read and/or write the format, whether the format
81 % supports the saving of more than one frame to the same file or blob,
82 % whether the format supports native in-memory I/O, and a brief
83 % description of the format.
85 % The format of the RegisterMATTEImage method is:
87 % size_t RegisterMATTEImage(void)
90 ModuleExport size_t RegisterMATTEImage(void)
95 entry=SetMagickInfo("MATTE");
96 entry->encoder=(EncodeImageHandler *) WriteMATTEImage;
97 entry->format_type=ExplicitFormatType;
98 entry->description=ConstantString("MATTE format");
99 entry->module=ConstantString("MATTE");
100 (void) RegisterMagickInfo(entry);
101 return(MagickImageCoderSignature);
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 % U n r e g i s t e r M A T T E I m a g e %
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 % UnregisterMATTEImage() removes format registrations made by the
116 % MATTE module from the list of supported formats.
118 % The format of the UnregisterMATTEImage method is:
120 % UnregisterMATTEImage(void)
123 ModuleExport void UnregisterMATTEImage(void)
125 (void) UnregisterMagickInfo("MATTE");
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 % W r i t e M A T T E I m a g e %
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 % WriteMATTEImage() writes an image of matte bytes to a file. It consists of
140 % data from the matte component of the image [0..255].
142 % The format of the WriteMATTEImage method is:
144 % MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
145 % Image *image,ExceptionInfo *exception)
147 % A description of each parameter follows.
149 % o image_info: the image info.
151 % o image: The image.
153 % o exception: return any errors or warnings in this structure.
156 static MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
157 Image *image,ExceptionInfo *exception)
165 register const Quantum
177 if (image->matte == MagickFalse)
178 ThrowWriterException(CoderError,"ImageDoesNotHaveAAlphaChannel");
179 matte_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
180 if (matte_image == (Image *) NULL)
182 (void) SetImageType(matte_image,TrueColorMatteType,exception);
183 matte_image->matte=MagickFalse;
185 Convert image to matte pixels.
187 for (y=0; y < (ssize_t) image->rows; y++)
189 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
190 q=QueueAuthenticPixels(matte_image,0,y,matte_image->columns,1,exception);
191 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
193 for (x=0; x < (ssize_t) image->columns; x++)
195 SetPixelRed(matte_image,GetPixelAlpha(image,p),q);
196 SetPixelGreen(matte_image,GetPixelAlpha(image,p),q);
197 SetPixelBlue(matte_image,GetPixelAlpha(image,p),q);
198 SetPixelAlpha(matte_image,OpaqueAlpha,q);
199 p+=GetPixelChannels(image);
200 q+=GetPixelChannels(matte_image);
202 if (SyncAuthenticPixels(matte_image,exception) == MagickFalse)
204 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
206 if (status == MagickFalse)
209 (void) FormatLocaleString(matte_image->filename,MaxTextExtent,
210 "MIFF:%s",image->filename);
211 status=WriteImage(image_info,matte_image,exception);
212 matte_image=DestroyImage(matte_image);