blob: 8c069705c8b4c8d423cb15e0eb8da5ff17b5478b [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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 %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
cristyb56bb242014-11-25 17:12:48 +000020% Copyright 1999-2015 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*/
cristy4c08aed2011-07-01 19:47:50 +000042#include "MagickCore/studio.h"
43#include "MagickCore/blob.h"
44#include "MagickCore/blob-private.h"
45#include "MagickCore/cache.h"
46#include "MagickCore/color.h"
47#include "MagickCore/color-private.h"
48#include "MagickCore/colorspace-private.h"
49#include "MagickCore/exception.h"
50#include "MagickCore/exception-private.h"
51#include "MagickCore/image.h"
52#include "MagickCore/image-private.h"
53#include "MagickCore/list.h"
54#include "MagickCore/magick.h"
55#include "MagickCore/memory_.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"
cristy3ed852e2009-09-05 21:47:34 +000061
62/*
63 Forward declarations.
64*/
65static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +000066 WriteNULLImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +000067
68/*
69%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70% %
71% %
72% %
73% R e a d N U L L I m a g e %
74% %
75% %
76% %
77%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78%
79% ReadNULLImage creates a constant image and initializes it to the
80% X server color as specified by the filename. It allocates the memory
81% necessary for the new Image structure and returns a pointer to the new
82% image.
83%
84% The format of the ReadNULLImage method is:
85%
86% Image *ReadNULLImage(const ImageInfo *image_info,
87% ExceptionInfo *exception)
88%
89% A description of each parameter follows:
90%
91% o image_info: the image info.
92%
93% o exception: return any errors or warnings in this structure.
94%
95*/
96static Image *ReadNULLImage(const ImageInfo *image_info,
97 ExceptionInfo *exception)
98{
99 Image
100 *image;
101
cristyacabb842014-12-14 23:36:33 +0000102 MagickBooleanType
103 status;
104
cristy4c08aed2011-07-01 19:47:50 +0000105 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +0000106 background;
107
cristybb503372010-05-27 20:51:26 +0000108 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000109 x;
110
cristy4c08aed2011-07-01 19:47:50 +0000111 register Quantum
cristy3ed852e2009-09-05 21:47:34 +0000112 *q;
113
cristyaff6d802011-04-26 01:46:31 +0000114 ssize_t
115 y;
116
cristy3ed852e2009-09-05 21:47:34 +0000117 /*
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);
cristy9950d572011-10-01 18:22:35 +0000127 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000128 if (image->columns == 0)
129 image->columns=1;
130 if (image->rows == 0)
131 image->rows=1;
cristyacabb842014-12-14 23:36:33 +0000132 status=SetImageExtent(image,image->columns,image->rows,exception);
133 if (status == MagickFalse)
134 return(DestroyImageList(image));
dirkbfdd5bc2014-11-04 19:47:44 +0000135 ConformPixelInfo(image,&image->background_color,&background,exception);
cristy8a46d822012-08-28 23:32:39 +0000136 image->alpha_trait=BlendPixelTrait;
cristya19f1d72012-08-07 18:24:38 +0000137 background.alpha=(double) TransparentAlpha;
cristybb503372010-05-27 20:51:26 +0000138 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000139 {
140 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000141 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000142 break;
cristybb503372010-05-27 20:51:26 +0000143 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000144 {
cristy803640d2011-11-17 02:11:32 +0000145 SetPixelInfoPixel(image,&background,q);
cristyed231572011-07-14 02:18:59 +0000146 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000147 }
148 if (SyncAuthenticPixels(image,exception) == MagickFalse)
149 break;
150 }
151 return(GetFirstImageInList(image));
152}
153
154/*
155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156% %
157% %
158% %
159% R e g i s t e r N U L L I m a g e %
160% %
161% %
162% %
163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164%
165% RegisterNULLImage() adds attributes for the NULL image format to
166% the list of supported formats. The attributes include the image format
167% tag, a method to read and/or write the format, whether the format
168% supports the saving of more than one frame to the same file or blob,
169% whether the format supports native in-memory I/O, and a brief
170% description of the format.
171%
172% The format of the RegisterNULLImage method is:
173%
cristybb503372010-05-27 20:51:26 +0000174% size_t RegisterNULLImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000175%
176*/
cristybb503372010-05-27 20:51:26 +0000177ModuleExport size_t RegisterNULLImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000178{
179 MagickInfo
180 *entry;
181
182 entry=SetMagickInfo("NULL");
183 entry->decoder=(DecodeImageHandler *) ReadNULLImage;
184 entry->encoder=(EncodeImageHandler *) WriteNULLImage;
185 entry->adjoin=MagickFalse;
cristy009d7392010-07-25 22:08:41 +0000186 entry->format_type=ImplicitFormatType;
cristy3ed852e2009-09-05 21:47:34 +0000187 entry->description=ConstantString("Constant image of uniform color");
188 entry->module=ConstantString("NULL");
189 (void) RegisterMagickInfo(entry);
190 return(MagickImageCoderSignature);
191}
192
193/*
194%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195% %
196% %
197% %
198% U n r e g i s t e r N U L L I m a g e %
199% %
200% %
201% %
202%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203%
204% UnregisterNULLImage() removes format registrations made by the
205% NULL module from the list of supported formats.
206%
207% The format of the UnregisterNULLImage method is:
208%
209% UnregisterNULLImage(void)
210%
211*/
212ModuleExport void UnregisterNULLImage(void)
213{
214 (void) UnregisterMagickInfo("NULL");
215}
216
217/*
218%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219% %
220% %
221% %
222% W r i t e N U L L I m a g e %
223% %
224% %
225% %
226%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227%
228% WriteNULLImage writes no output at all. It is useful when specified
229% as an output format when profiling.
230%
231% The format of the WriteNULLImage method is:
232%
233% MagickBooleanType WriteNULLImage(const ImageInfo *image_info,
cristy1e178e72011-08-28 19:44:34 +0000234% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000235%
236% A description of each parameter follows.
237%
238% o image_info: the image info.
239%
240% o image: The image.
241%
cristy1e178e72011-08-28 19:44:34 +0000242% o exception: return any errors or warnings in this structure.
243%
cristy3ed852e2009-09-05 21:47:34 +0000244*/
245static MagickBooleanType WriteNULLImage(const ImageInfo *image_info,
cristy1e178e72011-08-28 19:44:34 +0000246 Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000247{
248 assert(image_info != (const ImageInfo *) NULL);
249 assert(image_info->signature == MagickSignature);
250 assert(image != (Image *) NULL);
251 assert(image->signature == MagickSignature);
cristy1e178e72011-08-28 19:44:34 +0000252 assert(exception != (ExceptionInfo *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000253 if (image->debug != MagickFalse)
254 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
255 return(MagickTrue);
256}