root / ImageMagick / trunk / coders / null.c

Revision 11590, 10.1 kB (checked in by cristy, 7 weeks ago)
Line 
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3%                                                                             %
4%                                                                             %
5%                                                                             %
6%                        N   N  U   U  L      L                               %
7%                        NN  N  U   U  L      L                               %
8%                        N N N  U   U  L      L                               %
9%                        N  NN  U   U  L      L                               %
10%                        N   N   UUU   LLLLL  LLLLL                           %
11%                                                                             %
12%                                                                             %
13%                    Read/Write Image Of Uniform Color.                       %
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/color.h"
46#include "magick/color-private.h"
47#include "magick/colorspace-private.h"
48#include "magick/exception.h"
49#include "magick/exception-private.h"
50#include "magick/image.h"
51#include "magick/image-private.h"
52#include "magick/list.h"
53#include "magick/magick.h"
54#include "magick/memory_.h"
55#include "magick/pixel-private.h"
56#include "magick/quantum-private.h"
57#include "magick/static.h"
58#include "magick/string_.h"
59#include "magick/module.h"
60
61/*
62  Forward declarations.
63*/
64static MagickBooleanType
65  WriteNULLImage(const ImageInfo *,Image *);
66
67/*
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69%                                                                             %
70%                                                                             %
71%                                                                             %
72%   R e a d N U L L I m a g e                                                 %
73%                                                                             %
74%                                                                             %
75%                                                                             %
76%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77%
78%  ReadNULLImage creates a constant image and initializes it to the
79%  X server color as specified by the filename.  It allocates the memory
80%  necessary for the new Image structure and returns a pointer to the new
81%  image.
82%
83%  The format of the ReadNULLImage method is:
84%
85%      Image *ReadNULLImage(const ImageInfo *image_info,
86%        ExceptionInfo *exception)
87%
88%  A description of each parameter follows:
89%
90%    o image_info: the image info.
91%
92%    o exception: return any errors or warnings in this structure.
93%
94%
95*/
96static Image *ReadNULLImage(const ImageInfo *image_info,
97  ExceptionInfo *exception)
98{
99  Image
100    *image;
101
102  long
103    y;
104
105  MagickPixelPacket
106    background;
107
108  register IndexPacket
109    *indexes;
110
111  register long
112    x;
113
114  register PixelPacket
115    *q;
116
117  /*
118    Initialize Image structure.
119  */
120  assert(image_info != (const ImageInfo *) NULL);
121  assert(image_info->signature == MagickSignature);
122  if (image_info->debug != MagickFalse)
123    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
124      image_info->filename);
125  assert(exception != (ExceptionInfo *) NULL);
126  assert(exception->signature == MagickSignature);
127  image=AcquireImage(image_info);
128  if (image->columns == 0)
129    image->columns=1;
130  if (image->rows == 0)
131    image->rows=1;
132  image->matte=MagickTrue;
133  GetMagickPixelPacket(image,&background);
134  background.opacity=(MagickRealType) TransparentOpacity;
135  if (image->colorspace == CMYKColorspace)
136    ConvertRGBToCMYK(&background);
137  if (SetImageExtent(image,0,0) == MagickFalse)
138    {
139      InheritException(exception,&image->exception);
140      return(DestroyImageList(image));
141    }
142  for (y=0; y < (long) image->rows; y++)
143  {
144    q=SetImagePixels(image,0,y,image->columns,1);
145    if (q == (PixelPacket *) NULL)
146      break;
147    indexes=GetIndexes(image);
148    for (x=0; x < (long) image->columns; x++)
149    {
150      SetPixelPacket(image,&background,q,indexes);
151      q++;
152      indexes++;
153    }
154    if (SyncImagePixels(image) == MagickFalse)
155      break;
156  }
157  return(GetFirstImageInList(image));
158}
159
160/*
161%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162%                                                                             %
163%                                                                             %
164%                                                                             %
165%   R e g i s t e r N U L L I m a g e                                         %
166%                                                                             %
167%                                                                             %
168%                                                                             %
169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170%
171%  RegisterNULLImage() adds attributes for the NULL image format to
172%  the list of supported formats.  The attributes include the image format
173%  tag, a method to read and/or write the format, whether the format
174%  supports the saving of more than one frame to the same file or blob,
175%  whether the format supports native in-memory I/O, and a brief
176%  description of the format.
177%
178%  The format of the RegisterNULLImage method is:
179%
180%      unsigned long RegisterNULLImage(void)
181%
182*/
183ModuleExport unsigned long RegisterNULLImage(void)
184{
185  MagickInfo
186    *entry;
187
188  entry=SetMagickInfo("NULL");
189  entry->decoder=(DecodeImageHandler *) ReadNULLImage;
190  entry->encoder=(EncodeImageHandler *) WriteNULLImage;
191  entry->adjoin=MagickFalse;
192  entry->format_type=ImplicitFormatType;
193  entry->description=ConstantString("Constant image of uniform color");
194  entry->module=ConstantString("NULL");
195  (void) RegisterMagickInfo(entry);
196  return(MagickImageCoderSignature);
197}
198
199/*
200%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201%                                                                             %
202%                                                                             %
203%                                                                             %
204%   U n r e g i s t e r N U L L I m a g e                                     %
205%                                                                             %
206%                                                                             %
207%                                                                             %
208%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209%
210%  UnregisterNULLImage() removes format registrations made by the
211%  NULL module from the list of supported formats.
212%
213%  The format of the UnregisterNULLImage method is:
214%
215%      UnregisterNULLImage(void)
216%
217*/
218ModuleExport void UnregisterNULLImage(void)
219{
220  (void) UnregisterMagickInfo("NULL");
221}
222
223/*
224%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225%                                                                             %
226%                                                                             %
227%                                                                             %
228%   W r i t e N U L L I m a g e                                               %
229%                                                                             %
230%                                                                             %
231%                                                                             %
232%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233%
234%  WriteNULLImage writes no output at all. It is useful when specified
235%  as an output format when profiling.
236%
237%  The format of the WriteNULLImage method is:
238%
239%      MagickBooleanType WriteNULLImage(const ImageInfo *image_info,
240%        Image *image)
241%
242%  A description of each parameter follows.
243%
244%    o image_info: the image info.
245%
246%    o image:  The image.
247%
248%
249*/
250static MagickBooleanType WriteNULLImage(const ImageInfo *image_info,
251  Image *image)
252{
253  assert(image_info != (const ImageInfo *) NULL);
254  assert(image_info->signature == MagickSignature);
255  assert(image != (Image *) NULL);
256  assert(image->signature == MagickSignature);
257  if (image->debug != MagickFalse)
258    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
259  return(MagickTrue);
260}
Note: See TracBrowser for help on using the browser.