cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 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 % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | b56bb24 | 2014-11-25 17:12:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % 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 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
cristy | e37eaeb | 2012-07-10 13:52:23 +0000 | [diff] [blame] | 43 | #include "MagickCore/attribute.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
cristy | f13a9a3 | 2013-05-27 15:23:07 +0000 | [diff] [blame] | 46 | #include "MagickCore/channel.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 47 | #include "MagickCore/color.h" |
| 48 | #include "MagickCore/color-private.h" |
cristy | 3d9f5ba | 2012-06-26 13:37:31 +0000 | [diff] [blame] | 49 | #include "MagickCore/colorspace-private.h" |
cristy | a5e4eea | 2014-08-01 16:18:11 +0000 | [diff] [blame] | 50 | #include "MagickCore/constitute.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 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" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 66 | |
| 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 | */ |
| 95 | static Image *ReadGRADIENTImage(const ImageInfo *image_info, |
| 96 | ExceptionInfo *exception) |
| 97 | { |
| 98 | char |
| 99 | colorname[MaxTextExtent]; |
| 100 | |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 101 | Image |
| 102 | *image; |
| 103 | |
cristy | a5e4eea | 2014-08-01 16:18:11 +0000 | [diff] [blame] | 104 | ImageInfo |
| 105 | *read_info; |
| 106 | |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 107 | MagickBooleanType |
cristy | bbdf0cf | 2012-07-12 11:57:42 +0000 | [diff] [blame] | 108 | icc_color, |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 109 | status; |
| 110 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 111 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | start_color, |
| 113 | stop_color; |
| 114 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 115 | /* |
| 116 | Initialize Image structure. |
| 117 | */ |
| 118 | assert(image_info != (const ImageInfo *) NULL); |
| 119 | assert(image_info->signature == MagickSignature); |
| 120 | if (image_info->debug != MagickFalse) |
| 121 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 122 | image_info->filename); |
| 123 | assert(exception != (ExceptionInfo *) NULL); |
| 124 | assert(exception->signature == MagickSignature); |
cristy | a5e4eea | 2014-08-01 16:18:11 +0000 | [diff] [blame] | 125 | read_info=CloneImageInfo(image_info); |
| 126 | SetImageInfoBlob(read_info,(void *) NULL,0); |
cristy | d995bf6 | 2014-08-01 16:24:14 +0000 | [diff] [blame] | 127 | (void) CopyMagickString(colorname,image_info->filename,MaxTextExtent); |
| 128 | (void) sscanf(image_info->filename,"%[^-]",colorname); |
cristy | e8ab548 | 2014-08-01 16:20:54 +0000 | [diff] [blame] | 129 | (void) FormatLocaleString(read_info->filename,MaxTextExtent,"xc:%s", |
cristy | d995bf6 | 2014-08-01 16:24:14 +0000 | [diff] [blame] | 130 | colorname); |
cristy | a5e4eea | 2014-08-01 16:18:11 +0000 | [diff] [blame] | 131 | image=ReadImage(read_info,exception); |
| 132 | read_info=DestroyImageInfo(read_info); |
| 133 | if (image == (Image *) NULL) |
| 134 | return((Image *) NULL); |
cristy | 44f7c9c | 2014-11-14 11:01:38 +0000 | [diff] [blame] | 135 | (void) SetImageAlpha(image,(Quantum) TransparentAlpha,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 136 | (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent); |
cristy | bbdf0cf | 2012-07-12 11:57:42 +0000 | [diff] [blame] | 137 | icc_color=MagickFalse; |
| 138 | if (LocaleCompare(colorname,"icc") == 0) |
| 139 | { |
| 140 | (void) ConcatenateMagickString(colorname,"-",MaxTextExtent); |
| 141 | (void) sscanf(image_info->filename,"%*[^-]-%[^-]",colorname+4); |
| 142 | icc_color=MagickTrue; |
| 143 | } |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 144 | status=QueryColorCompliance(colorname,AllCompliance,&start_color,exception); |
| 145 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 146 | { |
| 147 | image=DestroyImage(image); |
| 148 | return((Image *) NULL); |
| 149 | } |
cristy | f212a78 | 2013-11-16 17:14:28 +0000 | [diff] [blame] | 150 | (void) SetImageColorspace(image,start_color.colorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 151 | (void) CopyMagickString(colorname,"white",MaxTextExtent); |
cristy | 1f22753 | 2015-01-25 12:42:56 +0000 | [diff] [blame] | 152 | if (GetPixelInfoIntensity(image,&start_color) > (QuantumRange/2.0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 153 | (void) CopyMagickString(colorname,"black",MaxTextExtent); |
cristy | bbdf0cf | 2012-07-12 11:57:42 +0000 | [diff] [blame] | 154 | if (icc_color == MagickFalse) |
cristy | df95b1a | 2014-05-21 16:50:56 +0000 | [diff] [blame] | 155 | (void) sscanf(image_info->filename,"%*[^-]-%[^-]",colorname); |
cristy | bbdf0cf | 2012-07-12 11:57:42 +0000 | [diff] [blame] | 156 | else |
cristy | df95b1a | 2014-05-21 16:50:56 +0000 | [diff] [blame] | 157 | (void) sscanf(image_info->filename,"%*[^-]-%*[^-]-%[^-]",colorname); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 158 | status=QueryColorCompliance(colorname,AllCompliance,&stop_color,exception); |
| 159 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 160 | { |
| 161 | image=DestroyImage(image); |
| 162 | return((Image *) NULL); |
| 163 | } |
cristy | 029fc7e | 2014-11-14 01:32:19 +0000 | [diff] [blame] | 164 | image->alpha_trait=start_color.alpha_trait; |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 165 | if (stop_color.alpha_trait != UndefinedPixelTrait) |
cristy | fc88f4c | 2014-11-14 01:09:20 +0000 | [diff] [blame] | 166 | image->alpha_trait=stop_color.alpha_trait; |
cristy | 9e1ac31 | 2012-06-20 11:53:02 +0000 | [diff] [blame] | 167 | status=GradientImage(image,LocaleCompare(image_info->magick,"GRADIENT") == 0 ? |
cristy | 189e84c | 2011-08-27 18:08:53 +0000 | [diff] [blame] | 168 | LinearGradient : RadialGradient,PadSpread,&start_color,&stop_color, |
| 169 | exception); |
cristy | 9e1ac31 | 2012-06-20 11:53:02 +0000 | [diff] [blame] | 170 | if (status == MagickFalse) |
| 171 | { |
| 172 | image=DestroyImageList(image); |
| 173 | return((Image *) NULL); |
| 174 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 175 | return(GetFirstImageInList(image)); |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 180 | % % |
| 181 | % % |
| 182 | % % |
| 183 | % R e g i s t e r G R A D I E N T I m a g e % |
| 184 | % % |
| 185 | % % |
| 186 | % % |
| 187 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 188 | % |
| 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. |
| 195 | % |
| 196 | % The format of the RegisterGRADIENTImage method is: |
| 197 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 198 | % size_t RegisterGRADIENTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 199 | % |
| 200 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 201 | ModuleExport size_t RegisterGRADIENTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 202 | { |
| 203 | MagickInfo |
| 204 | *entry; |
| 205 | |
| 206 | entry=SetMagickInfo("GRADIENT"); |
| 207 | entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 208 | entry->flags^=CoderAdjoinFlag; |
| 209 | entry->flags|=CoderRawSupportFlag; |
cristy | 009d739 | 2010-07-25 22:08:41 +0000 | [diff] [blame] | 210 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 211 | entry->description=ConstantString("Gradual linear passing from one shade to " |
| 212 | "another"); |
| 213 | entry->module=ConstantString("GRADIENT"); |
| 214 | (void) RegisterMagickInfo(entry); |
| 215 | entry=SetMagickInfo("RADIAL-GRADIENT"); |
| 216 | entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 217 | entry->flags^=CoderAdjoinFlag; |
| 218 | entry->flags|=CoderRawSupportFlag; |
cristy | 009d739 | 2010-07-25 22:08:41 +0000 | [diff] [blame] | 219 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 220 | entry->description=ConstantString("Gradual radial passing from one shade to " |
| 221 | "another"); |
| 222 | entry->module=ConstantString("GRADIENT"); |
| 223 | (void) RegisterMagickInfo(entry); |
| 224 | return(MagickImageCoderSignature); |
| 225 | } |
| 226 | |
| 227 | /* |
| 228 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 229 | % % |
| 230 | % % |
| 231 | % % |
| 232 | % U n r e g i s t e r G R A D I E N T I m a g e % |
| 233 | % % |
| 234 | % % |
| 235 | % % |
| 236 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 237 | % |
| 238 | % UnregisterGRADIENTImage() removes format registrations made by the |
| 239 | % GRADIENT module from the list of supported formats. |
| 240 | % |
| 241 | % The format of the UnregisterGRADIENTImage method is: |
| 242 | % |
| 243 | % UnregisterGRADIENTImage(void) |
| 244 | % |
| 245 | */ |
| 246 | ModuleExport void UnregisterGRADIENTImage(void) |
| 247 | { |
| 248 | (void) UnregisterMagickInfo("RADIAL-GRADIENT"); |
| 249 | (void) UnregisterMagickInfo("GRADIENT"); |
| 250 | } |