blob: f6895bf2d967af41adadb411548f8b655fc34eb7 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% GGGG RRRR AAA DDDD IIIII EEEEE N N TTTTT %
7% G R R A A D D I E NN N T %
8% G GG RRRR AAAAA D D I EEE N N N T %
9% G G R R A A D D I E N NN T %
10% GGG R R A A DDDD IIIII EEEEE N N T %
11% %
12% %
13% Read An Image Filled Using Gradient. %
14% %
15% Software Design %
16% John Cristy %
17% July 1992 %
18% %
19% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 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/color.h"
46#include "MagickCore/color-private.h"
47#include "MagickCore/draw.h"
48#include "MagickCore/exception.h"
49#include "MagickCore/exception-private.h"
50#include "MagickCore/image.h"
51#include "MagickCore/image-private.h"
52#include "MagickCore/list.h"
53#include "MagickCore/magick.h"
54#include "MagickCore/memory_.h"
55#include "MagickCore/paint.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"
61#include "MagickCore/studio.h"
cristy3ed852e2009-09-05 21:47:34 +000062
63/*
64%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65% %
66% %
67% %
68% R e a d G R A D I E N T I m a g e %
69% %
70% %
71% %
72%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73%
74% ReadGRADIENTImage creates a gradient image and initializes it to
75% the color range as specified by the filename. It allocates the memory
76% necessary for the new Image structure and returns a pointer to the new
77% image.
78%
79% The format of the ReadGRADIENTImage method is:
80%
81% Image *ReadGRADIENTImage(const ImageInfo *image_info,
82% ExceptionInfo *exception)
83%
84% A description of each parameter follows:
85%
86% o image_info: the image info.
87%
88% o exception: return any errors or warnings in this structure.
89%
90*/
91static Image *ReadGRADIENTImage(const ImageInfo *image_info,
92 ExceptionInfo *exception)
93{
94 char
95 colorname[MaxTextExtent];
96
cristy9950d572011-10-01 18:22:35 +000097 Image
98 *image;
99
100 MagickBooleanType
101 status;
102
cristy101ab702011-10-13 13:06:32 +0000103 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +0000104 start_color,
105 stop_color;
106
cristy3ed852e2009-09-05 21:47:34 +0000107 /*
108 Initialize Image structure.
109 */
110 assert(image_info != (const ImageInfo *) NULL);
111 assert(image_info->signature == MagickSignature);
112 if (image_info->debug != MagickFalse)
113 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
114 image_info->filename);
115 assert(exception != (ExceptionInfo *) NULL);
116 assert(exception->signature == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000117 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000118 if ((image->columns == 0) || (image->rows == 0))
119 ThrowReaderException(OptionError,"MustSpecifyImageSize");
cristye941a752011-10-15 01:52:48 +0000120 (void) SetImageAlpha(image,(Quantum) TransparentAlpha,exception);
cristy3ed852e2009-09-05 21:47:34 +0000121 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
122 (void) CopyMagickString(colorname,image_info->filename,MaxTextExtent);
123 (void) sscanf(image_info->filename,"%[^-]",colorname);
cristy9950d572011-10-01 18:22:35 +0000124 status=QueryColorCompliance(colorname,AllCompliance,&start_color,exception);
125 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000126 {
127 image=DestroyImage(image);
128 return((Image *) NULL);
129 }
130 (void) CopyMagickString(colorname,"white",MaxTextExtent);
cristy101ab702011-10-13 13:06:32 +0000131 if (GetPixelInfoIntensity(&start_color) > (Quantum) (QuantumRange/2))
cristy3ed852e2009-09-05 21:47:34 +0000132 (void) CopyMagickString(colorname,"black",MaxTextExtent);
133 (void) sscanf(image_info->filename,"%*[^-]-%s",colorname);
cristy9950d572011-10-01 18:22:35 +0000134 status=QueryColorCompliance(colorname,AllCompliance,&stop_color,exception);
135 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000136 {
137 image=DestroyImage(image);
138 return((Image *) NULL);
139 }
140 (void) GradientImage(image,LocaleCompare(image_info->magick,"GRADIENT") == 0 ?
cristy189e84c2011-08-27 18:08:53 +0000141 LinearGradient : RadialGradient,PadSpread,&start_color,&stop_color,
142 exception);
cristy3ed852e2009-09-05 21:47:34 +0000143 return(GetFirstImageInList(image));
144}
145
146/*
147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148% %
149% %
150% %
151% R e g i s t e r G R A D I E N T I m a g e %
152% %
153% %
154% %
155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156%
157% RegisterGRADIENTImage() adds attributes for the GRADIENT image format
158% to the list of supported formats. The attributes include the image format
159% tag, a method to read and/or write the format, whether the format
160% supports the saving of more than one frame to the same file or blob,
161% whether the format supports native in-memory I/O, and a brief
162% description of the format.
163%
164% The format of the RegisterGRADIENTImage method is:
165%
cristybb503372010-05-27 20:51:26 +0000166% size_t RegisterGRADIENTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000167%
168*/
cristybb503372010-05-27 20:51:26 +0000169ModuleExport size_t RegisterGRADIENTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000170{
171 MagickInfo
172 *entry;
173
174 entry=SetMagickInfo("GRADIENT");
175 entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage;
176 entry->adjoin=MagickFalse;
177 entry->raw=MagickTrue;
cristy009d7392010-07-25 22:08:41 +0000178 entry->format_type=ImplicitFormatType;
cristy3ed852e2009-09-05 21:47:34 +0000179 entry->description=ConstantString("Gradual linear passing from one shade to "
180 "another");
181 entry->module=ConstantString("GRADIENT");
182 (void) RegisterMagickInfo(entry);
183 entry=SetMagickInfo("RADIAL-GRADIENT");
184 entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage;
185 entry->adjoin=MagickFalse;
186 entry->raw=MagickTrue;
cristy009d7392010-07-25 22:08:41 +0000187 entry->format_type=ImplicitFormatType;
cristy3ed852e2009-09-05 21:47:34 +0000188 entry->description=ConstantString("Gradual radial passing from one shade to "
189 "another");
190 entry->module=ConstantString("GRADIENT");
191 (void) RegisterMagickInfo(entry);
192 return(MagickImageCoderSignature);
193}
194
195/*
196%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197% %
198% %
199% %
200% U n r e g i s t e r G R A D I E N T I m a g e %
201% %
202% %
203% %
204%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205%
206% UnregisterGRADIENTImage() removes format registrations made by the
207% GRADIENT module from the list of supported formats.
208%
209% The format of the UnregisterGRADIENTImage method is:
210%
211% UnregisterGRADIENTImage(void)
212%
213*/
214ModuleExport void UnregisterGRADIENTImage(void)
215{
216 (void) UnregisterMagickInfo("RADIAL-GRADIENT");
217 (void) UnregisterMagickInfo("GRADIENT");
218}