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-2018 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 % https://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/attribute.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/constitute.h"
48 #include "MagickCore/exception.h"
49 #include "MagickCore/exception-private.h"
50 #include "MagickCore/image-private.h"
51 #include "MagickCore/list.h"
52 #include "MagickCore/magick.h"
53 #include "MagickCore/memory_.h"
54 #include "MagickCore/monitor.h"
55 #include "MagickCore/monitor-private.h"
56 #include "MagickCore/pixel-accessor.h"
57 #include "MagickCore/quantum-private.h"
58 #include "MagickCore/static.h"
59 #include "MagickCore/string_.h"
60 #include "MagickCore/module.h"
65 static MagickBooleanType
66 WriteMATTEImage(const ImageInfo *,Image *,ExceptionInfo *);
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 % R e g i s t e r M A T T E I m a g e %
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 % RegisterMATTEImage() adds attributes for the MATTE image format to
80 % the list of supported formats. The attributes include the image format
81 % tag, a method to read and/or write the format, whether the format
82 % supports the saving of more than one frame to the same file or blob,
83 % whether the format supports native in-memory I/O, and a brief
84 % description of the format.
86 % The format of the RegisterMATTEImage method is:
88 % size_t RegisterMATTEImage(void)
91 ModuleExport size_t RegisterMATTEImage(void)
96 entry=AcquireMagickInfo("MATTE","MATTE","MATTE format");
97 entry->encoder=(EncodeImageHandler *) WriteMATTEImage;
98 entry->format_type=ExplicitFormatType;
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 % WriteMATTEImage() writes an image of matte bytes to a file. It consists of
139 % 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,
144 % Image *image,ExceptionInfo *exception)
146 % A description of each parameter follows.
148 % o image_info: the image info.
150 % o image: The image.
152 % o exception: return any errors or warnings in this structure.
155 static MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
156 Image *image,ExceptionInfo *exception)
167 register const Quantum
179 if (image->alpha_trait == UndefinedPixelTrait)
180 ThrowWriterException(CoderError,"ImageDoesNotHaveAnAlphaChannel");
181 matte_image=CloneImage(image,0,0,MagickTrue,exception);
182 if (matte_image == (Image *) NULL)
184 (void) SetImageType(matte_image,TrueColorAlphaType,exception);
185 matte_image->alpha_trait=UndefinedPixelTrait;
187 Convert image to matte pixels.
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 Quantum *) NULL) || (q == (Quantum *) NULL))
195 for (x=0; x < (ssize_t) image->columns; x++)
197 SetPixelRed(matte_image,GetPixelAlpha(image,p),q);
198 SetPixelGreen(matte_image,GetPixelAlpha(image,p),q);
199 SetPixelBlue(matte_image,GetPixelAlpha(image,p),q);
200 SetPixelAlpha(matte_image,OpaqueAlpha,q);
201 p+=GetPixelChannels(image);
202 q+=GetPixelChannels(matte_image);
204 if (SyncAuthenticPixels(matte_image,exception) == MagickFalse)
206 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
208 if (status == MagickFalse)
211 write_info=CloneImageInfo(image_info);
212 if ((*write_info->magick == '\0') ||
213 (LocaleCompare(write_info->magick,"MATTE") == 0))
214 (void) FormatLocaleString(matte_image->filename,MagickPathExtent,
215 "MIFF:%s",image->filename);
216 status=WriteImage(write_info,matte_image,exception);
217 write_info=DestroyImageInfo(write_info);
218 matte_image=DestroyImage(matte_image);