2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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 %
13 % Read An Image Filled Using Gradient. %
20 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #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/colorspace-private.h"
48 #include "MagickCore/draw.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/paint.h"
57 #include "MagickCore/pixel-accessor.h"
58 #include "MagickCore/quantum-private.h"
59 #include "MagickCore/static.h"
60 #include "MagickCore/string_.h"
61 #include "MagickCore/module.h"
62 #include "MagickCore/studio.h"
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 % R e a d G R A D I E N T I m a g e %
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 % ReadGRADIENTImage creates a gradient image and initializes it to
76 % the color range as specified by the filename. It allocates the memory
77 % necessary for the new Image structure and returns a pointer to the new
80 % The format of the ReadGRADIENTImage method is:
82 % Image *ReadGRADIENTImage(const ImageInfo *image_info,
83 % ExceptionInfo *exception)
85 % A description of each parameter follows:
87 % o image_info: the image info.
89 % o exception: return any errors or warnings in this structure.
92 static Image *ReadGRADIENTImage(const ImageInfo *image_info,
93 ExceptionInfo *exception)
96 colorname[MaxTextExtent];
109 Initialize Image structure.
111 assert(image_info != (const ImageInfo *) NULL);
112 assert(image_info->signature == MagickSignature);
113 if (image_info->debug != MagickFalse)
114 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
115 image_info->filename);
116 assert(exception != (ExceptionInfo *) NULL);
117 assert(exception->signature == MagickSignature);
118 image=AcquireImage(image_info,exception);
119 if ((image->columns == 0) || (image->rows == 0))
120 ThrowReaderException(OptionError,"MustSpecifyImageSize");
121 (void) SetImageAlpha(image,(Quantum) TransparentAlpha,exception);
122 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
123 (void) CopyMagickString(colorname,image_info->filename,MaxTextExtent);
124 (void) sscanf(image_info->filename,"%[^-]",colorname);
125 status=QueryColorCompliance(colorname,AllCompliance,&start_color,exception);
126 if (status == MagickFalse)
128 image=DestroyImage(image);
129 return((Image *) NULL);
131 (void) CopyMagickString(colorname,"white",MaxTextExtent);
132 if (GetPixelInfoIntensity(&start_color) > (Quantum) (QuantumRange/2))
133 (void) CopyMagickString(colorname,"black",MaxTextExtent);
134 (void) sscanf(image_info->filename,"%*[^-]-%s",colorname);
135 status=QueryColorCompliance(colorname,AllCompliance,&stop_color,exception);
136 if (status == MagickFalse)
138 image=DestroyImage(image);
139 return((Image *) NULL);
141 if (IssRGBColorspace(start_color.colorspace) != MagickFalse)
143 start_color.red=QuantumRange*DecompandsRGB(QuantumScale*
145 start_color.green=QuantumRange*DecompandsRGB(QuantumScale*
147 start_color.blue=QuantumRange*DecompandsRGB(QuantumScale*
150 if (IssRGBColorspace(stop_color.colorspace) != MagickFalse)
152 stop_color.red=QuantumRange*DecompandsRGB(QuantumScale*
154 stop_color.green=QuantumRange*DecompandsRGB(QuantumScale*
156 stop_color.blue=QuantumRange*DecompandsRGB(QuantumScale*
159 status=GradientImage(image,LocaleCompare(image_info->magick,"GRADIENT") == 0 ?
160 LinearGradient : RadialGradient,PadSpread,&start_color,&stop_color,
162 if (status == MagickFalse)
164 image=DestroyImageList(image);
165 return((Image *) NULL);
167 (void) SetImageColorspace(image,start_color.colorspace,exception);
168 if ((start_color.matte == MagickFalse) && (stop_color.matte == MagickFalse))
169 (void) SetImageAlphaChannel(image,DeactivateAlphaChannel,exception);
170 if (IssRGBColorspace(start_color.colorspace) != MagickFalse)
172 (void) SetImageColorspace(image,RGBColorspace,exception);
173 (void) TransformImageColorspace(image,sRGBColorspace,exception);
175 return(GetFirstImageInList(image));
179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 % R e g i s t e r G R A D I E N T I m a g e %
187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189 % RegisterGRADIENTImage() adds attributes for the GRADIENT image format
190 % to the list of supported formats. The attributes include the image format
191 % tag, a method to read and/or write the format, whether the format
192 % supports the saving of more than one frame to the same file or blob,
193 % whether the format supports native in-memory I/O, and a brief
194 % description of the format.
196 % The format of the RegisterGRADIENTImage method is:
198 % size_t RegisterGRADIENTImage(void)
201 ModuleExport size_t RegisterGRADIENTImage(void)
206 entry=SetMagickInfo("GRADIENT");
207 entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage;
208 entry->adjoin=MagickFalse;
209 entry->raw=MagickTrue;
210 entry->format_type=ImplicitFormatType;
211 entry->description=ConstantString("Gradual linear passing from one shade to "
213 entry->module=ConstantString("GRADIENT");
214 (void) RegisterMagickInfo(entry);
215 entry=SetMagickInfo("RADIAL-GRADIENT");
216 entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage;
217 entry->adjoin=MagickFalse;
218 entry->raw=MagickTrue;
219 entry->format_type=ImplicitFormatType;
220 entry->description=ConstantString("Gradual radial passing from one shade to "
222 entry->module=ConstantString("GRADIENT");
223 (void) RegisterMagickInfo(entry);
224 return(MagickImageCoderSignature);
228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 % U n r e g i s t e r G R A D I E N T I m a g e %
236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 % UnregisterGRADIENTImage() removes format registrations made by the
239 % GRADIENT module from the list of supported formats.
241 % The format of the UnregisterGRADIENTImage method is:
243 % UnregisterGRADIENTImage(void)
246 ModuleExport void UnregisterGRADIENTImage(void)
248 (void) UnregisterMagickInfo("RADIAL-GRADIENT");
249 (void) UnregisterMagickInfo("GRADIENT");