blob: 6324bdcfd995b6c2fa6efcdfe97ec333d705fcb0 [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 %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
Cristy7ce65e72015-12-12 18:03:16 -050020% Copyright 1999-2016 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"
cristye37eaeb2012-07-10 13:52:23 +000043#include "MagickCore/attribute.h"
cristy4c08aed2011-07-01 19:47:50 +000044#include "MagickCore/blob.h"
45#include "MagickCore/blob-private.h"
cristyf13a9a32013-05-27 15:23:07 +000046#include "MagickCore/channel.h"
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickCore/color.h"
48#include "MagickCore/color-private.h"
cristy3d9f5ba2012-06-26 13:37:31 +000049#include "MagickCore/colorspace-private.h"
cristya5e4eea2014-08-01 16:18:11 +000050#include "MagickCore/constitute.h"
cristy4c08aed2011-07-01 19:47:50 +000051#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"
cristy3ed852e2009-09-05 21:47:34 +000066
67/*
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69% %
70% %
71% %
72% R e a d G R A D I E N T I m a g e %
73% %
74% %
75% %
76%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77%
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
81% image.
82%
83% The format of the ReadGRADIENTImage method is:
84%
85% Image *ReadGRADIENTImage(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*/
95static Image *ReadGRADIENTImage(const ImageInfo *image_info,
96 ExceptionInfo *exception)
97{
98 char
Cristy34aabc42015-09-05 08:12:48 -040099 colorname[MagickPathExtent+4];
cristy3ed852e2009-09-05 21:47:34 +0000100
cristy9950d572011-10-01 18:22:35 +0000101 Image
102 *image;
103
cristya5e4eea2014-08-01 16:18:11 +0000104 ImageInfo
105 *read_info;
106
cristy9950d572011-10-01 18:22:35 +0000107 MagickBooleanType
cristybbdf0cf2012-07-12 11:57:42 +0000108 icc_color,
cristy9950d572011-10-01 18:22:35 +0000109 status;
110
dirkb6f578b2015-07-12 17:56:39 +0000111 StopInfo
112 *stops;
cristy3ed852e2009-09-05 21:47:34 +0000113
cristy3ed852e2009-09-05 21:47:34 +0000114 /*
115 Initialize Image structure.
116 */
117 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000118 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000119 if (image_info->debug != MagickFalse)
120 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
121 image_info->filename);
122 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000123 assert(exception->signature == MagickCoreSignature);
cristya5e4eea2014-08-01 16:18:11 +0000124 read_info=CloneImageInfo(image_info);
125 SetImageInfoBlob(read_info,(void *) NULL,0);
cristy151b66d2015-04-15 10:50:31 +0000126 (void) CopyMagickString(colorname,image_info->filename,MagickPathExtent);
cristyd995bf62014-08-01 16:24:14 +0000127 (void) sscanf(image_info->filename,"%[^-]",colorname);
cristy151b66d2015-04-15 10:50:31 +0000128 (void) FormatLocaleString(read_info->filename,MagickPathExtent,"xc:%s",
cristyd995bf62014-08-01 16:24:14 +0000129 colorname);
cristya5e4eea2014-08-01 16:18:11 +0000130 image=ReadImage(read_info,exception);
131 read_info=DestroyImageInfo(read_info);
132 if (image == (Image *) NULL)
133 return((Image *) NULL);
cristy44f7c9c2014-11-14 11:01:38 +0000134 (void) SetImageAlpha(image,(Quantum) TransparentAlpha,exception);
cristy151b66d2015-04-15 10:50:31 +0000135 (void) CopyMagickString(image->filename,image_info->filename,MagickPathExtent);
cristybbdf0cf2012-07-12 11:57:42 +0000136 icc_color=MagickFalse;
137 if (LocaleCompare(colorname,"icc") == 0)
138 {
cristy151b66d2015-04-15 10:50:31 +0000139 (void) ConcatenateMagickString(colorname,"-",MagickPathExtent);
cristybbdf0cf2012-07-12 11:57:42 +0000140 (void) sscanf(image_info->filename,"%*[^-]-%[^-]",colorname+4);
141 icc_color=MagickTrue;
142 }
dirkb6f578b2015-07-12 17:56:39 +0000143 stops=(StopInfo *) AcquireQuantumMemory(2,sizeof(*stops));
144 if (stops == (StopInfo *) NULL)
145 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
146 stops[0].offset=0.0;
147 stops[1].offset=1.0;
148 status=QueryColorCompliance(colorname,AllCompliance,&stops[0].color,exception);
cristy9950d572011-10-01 18:22:35 +0000149 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000150 {
dirkb6f578b2015-07-12 17:56:39 +0000151 stops=(StopInfo *) RelinquishMagickMemory(stops);
cristy3ed852e2009-09-05 21:47:34 +0000152 image=DestroyImage(image);
153 return((Image *) NULL);
154 }
dirkb6f578b2015-07-12 17:56:39 +0000155 (void) SetImageColorspace(image,stops[0].color.colorspace,exception);
cristy151b66d2015-04-15 10:50:31 +0000156 (void) CopyMagickString(colorname,"white",MagickPathExtent);
dirkb6f578b2015-07-12 17:56:39 +0000157 if (GetPixelInfoIntensity(image,&stops[0].color) > (QuantumRange/2.0))
cristy151b66d2015-04-15 10:50:31 +0000158 (void) CopyMagickString(colorname,"black",MagickPathExtent);
cristybbdf0cf2012-07-12 11:57:42 +0000159 if (icc_color == MagickFalse)
cristydf95b1a2014-05-21 16:50:56 +0000160 (void) sscanf(image_info->filename,"%*[^-]-%[^-]",colorname);
cristybbdf0cf2012-07-12 11:57:42 +0000161 else
cristydf95b1a2014-05-21 16:50:56 +0000162 (void) sscanf(image_info->filename,"%*[^-]-%*[^-]-%[^-]",colorname);
dirkb6f578b2015-07-12 17:56:39 +0000163 status=QueryColorCompliance(colorname,AllCompliance,&stops[1].color,exception);
cristy9950d572011-10-01 18:22:35 +0000164 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000165 {
dirkb6f578b2015-07-12 17:56:39 +0000166 stops=(StopInfo *) RelinquishMagickMemory(stops);
cristy3ed852e2009-09-05 21:47:34 +0000167 image=DestroyImage(image);
168 return((Image *) NULL);
169 }
dirkb6f578b2015-07-12 17:56:39 +0000170 image->alpha_trait=stops[0].color.alpha_trait;
171 if (stops[1].color.alpha_trait != UndefinedPixelTrait)
172 image->alpha_trait=stops[1].color.alpha_trait;
cristy9e1ac312012-06-20 11:53:02 +0000173 status=GradientImage(image,LocaleCompare(image_info->magick,"GRADIENT") == 0 ?
dirkb6f578b2015-07-12 17:56:39 +0000174 LinearGradient : RadialGradient,PadSpread,stops,2,exception);
175 stops=(StopInfo *) RelinquishMagickMemory(stops);
cristy9e1ac312012-06-20 11:53:02 +0000176 if (status == MagickFalse)
177 {
178 image=DestroyImageList(image);
179 return((Image *) NULL);
180 }
cristy3ed852e2009-09-05 21:47:34 +0000181 return(GetFirstImageInList(image));
182}
183
184/*
185%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186% %
187% %
188% %
189% R e g i s t e r G R A D I E N T I m a g e %
190% %
191% %
192% %
193%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194%
195% RegisterGRADIENTImage() adds attributes for the GRADIENT image format
196% to the list of supported formats. The attributes include the image format
197% tag, a method to read and/or write the format, whether the format
198% supports the saving of more than one frame to the same file or blob,
199% whether the format supports native in-memory I/O, and a brief
200% description of the format.
201%
202% The format of the RegisterGRADIENTImage method is:
203%
cristybb503372010-05-27 20:51:26 +0000204% size_t RegisterGRADIENTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000205%
206*/
cristybb503372010-05-27 20:51:26 +0000207ModuleExport size_t RegisterGRADIENTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000208{
209 MagickInfo
210 *entry;
211
dirk06b627a2015-04-06 18:59:17 +0000212 entry=AcquireMagickInfo("GRADIENT","GRADIENT",
213 "Gradual linear passing from one shade to another");
cristy3ed852e2009-09-05 21:47:34 +0000214 entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage;
dirk08e9a112015-02-22 01:51:41 +0000215 entry->flags^=CoderAdjoinFlag;
216 entry->flags|=CoderRawSupportFlag;
cristy009d7392010-07-25 22:08:41 +0000217 entry->format_type=ImplicitFormatType;
cristy3ed852e2009-09-05 21:47:34 +0000218 (void) RegisterMagickInfo(entry);
dirk06b627a2015-04-06 18:59:17 +0000219 entry=AcquireMagickInfo("GRADIENT","RADIAL-GRADIENT",
220 "Gradual radial passing from one shade to another");
cristy3ed852e2009-09-05 21:47:34 +0000221 entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage;
dirk08e9a112015-02-22 01:51:41 +0000222 entry->flags^=CoderAdjoinFlag;
223 entry->flags|=CoderRawSupportFlag;
cristy009d7392010-07-25 22:08:41 +0000224 entry->format_type=ImplicitFormatType;
cristy3ed852e2009-09-05 21:47:34 +0000225 (void) RegisterMagickInfo(entry);
226 return(MagickImageCoderSignature);
227}
228
229/*
230%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231% %
232% %
233% %
234% U n r e g i s t e r G R A D I E N T I m a g e %
235% %
236% %
237% %
238%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239%
240% UnregisterGRADIENTImage() removes format registrations made by the
241% GRADIENT module from the list of supported formats.
242%
243% The format of the UnregisterGRADIENTImage method is:
244%
245% UnregisterGRADIENTImage(void)
246%
247*/
248ModuleExport void UnregisterGRADIENTImage(void)
249{
250 (void) UnregisterMagickInfo("RADIAL-GRADIENT");
251 (void) UnregisterMagickInfo("GRADIENT");
252}