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-2018 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 % https://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/attribute.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/channel.h"
47 #include "MagickCore/color.h"
48 #include "MagickCore/color-private.h"
49 #include "MagickCore/colorspace-private.h"
50 #include "MagickCore/constitute.h"
51 #include "MagickCore/draw.h"
52 #include "MagickCore/exception.h"
53 #include "MagickCore/exception-private.h"
54 #include "MagickCore/image.h"
55 #include "MagickCore/image-private.h"
56 #include "MagickCore/list.h"
57 #include "MagickCore/magick.h"
58 #include "MagickCore/memory_.h"
59 #include "MagickCore/paint.h"
60 #include "MagickCore/pixel-accessor.h"
61 #include "MagickCore/quantum-private.h"
62 #include "MagickCore/static.h"
63 #include "MagickCore/string_.h"
64 #include "MagickCore/module.h"
65 #include "MagickCore/studio.h"
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 % R e a d G R A D I E N T I m a g e %
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 % ReadGRADIENTImage creates a gradient image and initializes it to
79 % the color range as specified by the filename. It allocates the memory
80 % necessary for the new Image structure and returns a pointer to the new
83 % The format of the ReadGRADIENTImage method is:
85 % Image *ReadGRADIENTImage(const ImageInfo *image_info,
86 % ExceptionInfo *exception)
88 % A description of each parameter follows:
90 % o image_info: the image info.
92 % o exception: return any errors or warnings in this structure.
96 static Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception)
117 Initialize Image structure.
119 assert(image_info != (const ImageInfo *) NULL);
120 assert(image_info->signature == MagickCoreSignature);
121 if (image_info->debug != MagickFalse)
122 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
123 image_info->filename);
124 assert(exception != (ExceptionInfo *) NULL);
125 assert(exception->signature == MagickCoreSignature);
126 image=AcquireImage(image_info,exception);
127 if (image->columns == 0)
129 if (image->rows == 0)
131 status=SetImageExtent(image,image->columns,image->rows,exception);
132 if (status == MagickFalse)
133 return(DestroyImageList(image));
134 (void) CopyMagickString(image->filename,image_info->filename,
136 if (*image_info->filename == '\0')
137 pixel=image->background_color;
140 status=QueryColorCompliance((char *) image_info->filename,AllCompliance,
142 if (status == MagickFalse)
144 image=DestroyImage(image);
145 return((Image *) NULL);
148 (void) SetImageColorspace(image,pixel.colorspace,exception);
149 image->alpha_trait=pixel.alpha_trait;
150 for (y=0; y < (ssize_t) image->rows; y++)
152 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
153 if (q == (Quantum *) NULL)
155 for (x=0; x < (ssize_t) image->columns; x++)
157 SetPixelViaPixelInfo(image,&pixel,q);
158 q+=GetPixelChannels(image);
160 if (SyncAuthenticPixels(image,exception) == MagickFalse)
163 return(GetFirstImageInList(image));
166 static Image *ReadGRADIENTImage(const ImageInfo *image_info,
167 ExceptionInfo *exception)
170 colorname[MagickPathExtent+4];
186 Initialize Image structure.
188 assert(image_info != (const ImageInfo *) NULL);
189 assert(image_info->signature == MagickCoreSignature);
190 if (image_info->debug != MagickFalse)
191 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
192 image_info->filename);
193 assert(exception != (ExceptionInfo *) NULL);
194 assert(exception->signature == MagickCoreSignature);
195 read_info=CloneImageInfo(image_info);
196 SetImageInfoBlob(read_info,(void *) NULL,0);
197 (void) CopyMagickString(colorname,image_info->filename,MagickPathExtent);
198 (void) sscanf(image_info->filename,"%[^-]",colorname);
199 (void) CopyMagickString(read_info->filename,colorname,MagickPathExtent);
200 image=ReadXCImage(read_info,exception);
201 read_info=DestroyImageInfo(read_info);
202 if (image == (Image *) NULL)
203 return((Image *) NULL);
204 (void) SetImageAlpha(image,(Quantum) TransparentAlpha,exception);
205 (void) CopyMagickString(image->filename,image_info->filename,
207 icc_color=MagickFalse;
208 if (LocaleCompare(colorname,"icc") == 0)
210 (void) ConcatenateMagickString(colorname,"-",MagickPathExtent);
211 (void) sscanf(image_info->filename,"%*[^-]-%[^-]",colorname+4);
212 icc_color=MagickTrue;
214 stops=(StopInfo *) AcquireQuantumMemory(2,sizeof(*stops));
215 if (stops == (StopInfo *) NULL)
216 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
219 status=QueryColorCompliance(colorname,AllCompliance,&stops[0].color,
221 if (status == MagickFalse)
223 stops=(StopInfo *) RelinquishMagickMemory(stops);
224 image=DestroyImage(image);
225 return((Image *) NULL);
227 (void) SetImageColorspace(image,stops[0].color.colorspace,exception);
228 (void) CopyMagickString(colorname,"white",MagickPathExtent);
229 if (GetPixelInfoIntensity(image,&stops[0].color) > (QuantumRange/2.0))
230 (void) CopyMagickString(colorname,"black",MagickPathExtent);
231 if (icc_color == MagickFalse)
232 (void) sscanf(image_info->filename,"%*[^-]-%[^-]",colorname);
234 (void) sscanf(image_info->filename,"%*[^-]-%*[^-]-%[^-]",colorname);
235 status=QueryColorCompliance(colorname,AllCompliance,&stops[1].color,
237 if (status == MagickFalse)
239 stops=(StopInfo *) RelinquishMagickMemory(stops);
240 image=DestroyImage(image);
241 return((Image *) NULL);
243 image->alpha_trait=stops[0].color.alpha_trait;
244 if (stops[1].color.alpha_trait != UndefinedPixelTrait)
245 image->alpha_trait=stops[1].color.alpha_trait;
246 status=GradientImage(image,LocaleCompare(image_info->magick,"GRADIENT") == 0 ?
247 LinearGradient : RadialGradient,PadSpread,stops,2,exception);
248 stops=(StopInfo *) RelinquishMagickMemory(stops);
249 if (status == MagickFalse)
251 image=DestroyImageList(image);
252 return((Image *) NULL);
254 return(GetFirstImageInList(image));
258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 % R e g i s t e r G R A D I E N T I m a g e %
266 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268 % RegisterGRADIENTImage() adds attributes for the GRADIENT image format
269 % to the list of supported formats. The attributes include the image format
270 % tag, a method to read and/or write the format, whether the format
271 % supports the saving of more than one frame to the same file or blob,
272 % whether the format supports native in-memory I/O, and a brief
273 % description of the format.
275 % The format of the RegisterGRADIENTImage method is:
277 % size_t RegisterGRADIENTImage(void)
280 ModuleExport size_t RegisterGRADIENTImage(void)
285 entry=AcquireMagickInfo("GRADIENT","GRADIENT",
286 "Gradual linear passing from one shade to another");
287 entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage;
288 entry->flags^=CoderAdjoinFlag;
289 entry->flags|=CoderRawSupportFlag;
290 entry->format_type=ImplicitFormatType;
291 (void) RegisterMagickInfo(entry);
292 entry=AcquireMagickInfo("GRADIENT","RADIAL-GRADIENT",
293 "Gradual radial passing from one shade to another");
294 entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage;
295 entry->flags^=CoderAdjoinFlag;
296 entry->flags|=CoderRawSupportFlag;
297 entry->format_type=ImplicitFormatType;
298 (void) RegisterMagickInfo(entry);
299 return(MagickImageCoderSignature);
303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307 % U n r e g i s t e r G R A D I E N T I m a g e %
311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 % UnregisterGRADIENTImage() removes format registrations made by the
314 % GRADIENT module from the list of supported formats.
316 % The format of the UnregisterGRADIENTImage method is:
318 % UnregisterGRADIENTImage(void)
321 ModuleExport void UnregisterGRADIENTImage(void)
323 (void) UnregisterMagickInfo("RADIAL-GRADIENT");
324 (void) UnregisterMagickInfo("GRADIENT");