blob: eb301c3618219950a31f8dc0cad3b7da20fa0121 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M AAA TTTTT TTTTT EEEEE %
7% MM MM A A T T E %
8% M M M AAAAA T T EEE %
9% M M A A T T E %
10% M M A A T T EEEEE %
11% %
12% %
13% Write Matte Channel To MIFF File. %
14% %
15% Software Design %
16% John Cristy %
17% July 1992 %
18% %
19% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 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*/
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"
59
60/*
61 Forward declarations.
62*/
63static MagickBooleanType
64 WriteMATTEImage(const ImageInfo *,Image *);
65
66/*
67%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68% %
69% %
70% %
71% R e g i s t e r M A T T E I m a g e %
72% %
73% %
74% %
75%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76%
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.
83%
84% The format of the RegisterMATTEImage method is:
85%
cristybb503372010-05-27 20:51:26 +000086% size_t RegisterMATTEImage(void)
cristy3ed852e2009-09-05 21:47:34 +000087%
88*/
cristybb503372010-05-27 20:51:26 +000089ModuleExport size_t RegisterMATTEImage(void)
cristy3ed852e2009-09-05 21:47:34 +000090{
91 MagickInfo
92 *entry;
93
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);
101}
102
103/*
104%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105% %
106% %
107% %
108% U n r e g i s t e r M A T T E I m a g e %
109% %
110% %
111% %
112%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113%
114% UnregisterMATTEImage() removes format registrations made by the
115% MATTE module from the list of supported formats.
116%
117% The format of the UnregisterMATTEImage method is:
118%
119% UnregisterMATTEImage(void)
120%
121*/
122ModuleExport void UnregisterMATTEImage(void)
123{
124 (void) UnregisterMagickInfo("MATTE");
125}
126
127/*
128%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129% %
130% %
131% %
132% W r i t e M A T T E I m a g e %
133% %
134% %
135% %
136%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137%
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].
140%
141% The format of the WriteMATTEImage method is:
142%
143% MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
144% Image *image)
145%
146% A description of each parameter follows.
147%
148% o image_info: the image info.
149%
150% o image: The image.
151%
152*/
153static MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
154 Image *image)
155{
156 ExceptionInfo
157 *exception;
158
159 Image
160 *matte_image;
161
cristybb503372010-05-27 20:51:26 +0000162 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000163 y;
164
165 MagickBooleanType
166 status;
167
168 register const PixelPacket
169 *p;
170
cristybb503372010-05-27 20:51:26 +0000171 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000172 x;
173
174 register PixelPacket
175 *q;
176
177 if (image->matte == MagickFalse)
178 ThrowWriterException(CoderError,"ImageDoesNotHaveAAlphaChannel");
179 matte_image=CloneImage(image,image->columns,image->rows,MagickTrue,
180 &image->exception);
181 if (matte_image == (Image *) NULL)
182 return(MagickFalse);
183 (void) SetImageType(matte_image,TrueColorMatteType);
184 matte_image->matte=MagickFalse;
185 /*
186 Convert image to matte pixels.
187 */
188 exception=(&image->exception);
cristybb503372010-05-27 20:51:26 +0000189 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000190 {
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))
194 break;
cristybb503372010-05-27 20:51:26 +0000195 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000196 {
cristyce70c172010-01-07 17:15:30 +0000197 q->red=GetOpacityPixelComponent(p);
198 q->green=GetOpacityPixelComponent(p);
199 q->blue=GetOpacityPixelComponent(p);
200 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +0000201 p++;
202 q++;
203 }
204 if (SyncAuthenticPixels(matte_image,exception) == MagickFalse)
205 break;
cristycee97112010-05-28 00:44:52 +0000206 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
207 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000208 if (status == MagickFalse)
209 break;
210 }
211 (void) FormatMagickString(matte_image->filename,MaxTextExtent,
212 "MIFF:%s",image->filename);
213 status=WriteImage(image_info,matte_image);
214 matte_image=DestroyImage(matte_image);
215 return(status);
216}