root / ImageMagick / trunk / coders / matte.c

Revision 12035, 8.3 kB (checked in by cristy, 2 weeks ago)
Line 
1/*
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%                                                                             %
20%  Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization      %
21%  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/constitute.h"
46#include "magick/exception.h"
47#include "magick/exception-private.h"
48#include "magick/image-private.h"
49#include "magick/list.h"
50#include "magick/magick.h"
51#include "magick/memory_.h"
52#include "magick/monitor.h"
53#include "magick/monitor-private.h"
54#include "magick/quantum-private.h"
55#include "magick/static.h"
56#include "magick/string_.h"
57#include "magick/module.h"
58
59/*
60  Forward declarations.
61*/
62static MagickBooleanType
63  WriteMATTEImage(const ImageInfo *,Image *);
64
65/*
66%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67%                                                                             %
68%                                                                             %
69%                                                                             %
70%   R e g i s t e r M A T T E I m a g e                                       %
71%                                                                             %
72%                                                                             %
73%                                                                             %
74%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75%
76%  RegisterMATTEImage() adds attributes for the MATTE image format to
77%  the list of supported formats.  The attributes include the image format
78%  tag, a method to read and/or write the format, whether the format
79%  supports the saving of more than one frame to the same file or blob,
80%  whether the format supports native in-memory I/O, and a brief
81%  description of the format.
82%
83%  The format of the RegisterMATTEImage method is:
84%
85%      unsigned long RegisterMATTEImage(void)
86%
87*/
88ModuleExport unsigned long RegisterMATTEImage(void)
89{
90  MagickInfo
91    *entry;
92
93  entry=SetMagickInfo("MATTE");
94  entry->encoder=(EncodeImageHandler *) WriteMATTEImage;
95  entry->format_type=ExplicitFormatType;
96  entry->description=ConstantString("MATTE format");
97  entry->module=ConstantString("MATTE");
98  (void) RegisterMagickInfo(entry);
99  return(MagickImageCoderSignature);
100}
101
102/*
103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104%                                                                             %
105%                                                                             %
106%                                                                             %
107%   U n r e g i s t e r M A T T E I m a g e                                   %
108%                                                                             %
109%                                                                             %
110%                                                                             %
111%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112%
113%  UnregisterMATTEImage() removes format registrations made by the
114%  MATTE module from the list of supported formats.
115%
116%  The format of the UnregisterMATTEImage method is:
117%
118%      UnregisterMATTEImage(void)
119%
120*/
121ModuleExport void UnregisterMATTEImage(void)
122{
123  (void) UnregisterMagickInfo("MATTE");
124}
125
126/*
127%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128%                                                                             %
129%                                                                             %
130%                                                                             %
131%   W r i t e M A T T E I m a g e                                             %
132%                                                                             %
133%                                                                             %
134%                                                                             %
135%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136%
137%  Function WriteMATTEImage() writes an image of matte bytes to a file.  It
138%  consists of data from the matte component of the image [0..255].
139%
140%  The format of the WriteMATTEImage method is:
141%
142%      MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
143%        Image *image)
144%
145%  A description of each parameter follows.
146%
147%    o image_info: the image info.
148%
149%    o image:  The image.
150%
151*/
152static MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
153  Image *image)
154{
155  Image
156    *matte_image;
157
158  long
159    y;
160
161  MagickBooleanType
162    status;
163
164  register const PixelPacket
165    *p;
166
167  register long
168    x;
169
170  register PixelPacket
171    *q;
172
173  if (image->matte == MagickFalse)
174    ThrowWriterException(CoderError,"ImageDoesNotHaveAAlphaChannel");
175  matte_image=CloneImage(image,image->columns,image->rows,MagickTrue,
176    &image->exception);
177  if (matte_image == (Image *) NULL)
178    return(MagickFalse);
179  (void) SetImageType(matte_image,TrueColorMatteType);
180  matte_image->matte=MagickFalse;
181  /*
182    Convert image to matte pixels.
183  */
184  for (y=0; y < (long) image->rows; y++)
185  {
186    p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
187    q=SetImagePixels(matte_image,0,y,matte_image->columns,1);
188    if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
189      break;
190    for (x=0; x < (long) image->columns; x++)
191    {
192      q->red=p->opacity;
193      q->green=p->opacity;
194      q->blue=p->opacity;
195      q->opacity=OpaqueOpacity;
196      p++;
197      q++;
198    }
199    if (SyncImagePixels(matte_image) == MagickFalse)
200      break;
201    status=SetImageProgress(image,SaveImageTag,y,image->rows);
202    if (status == MagickFalse)
203      break;
204  }
205  (void) FormatMagickString(matte_image->filename,MaxTextExtent,
206    "MIFF:%s",image->filename);
207  status=WriteImage(image_info,matte_image);
208  matte_image=DestroyImage(matte_image);
209  return(status);
210}
Note: See TracBrowser for help on using the browser.