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 % 16 % Cristy % 17 % July 1992 % 18 % % 19 % % 20 % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization % 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 /* 41 Include declarations. 42 */ 43 #include "MagickCore/studio.h" 44 #include "MagickCore/attribute.h" 45 #include "MagickCore/blob.h" 46 #include "MagickCore/blob-private.h" 47 #include "MagickCore/channel.h" 48 #include "MagickCore/color.h" 49 #include "MagickCore/color-private.h" 50 #include "MagickCore/colorspace-private.h" 51 #include "MagickCore/constitute.h" 52 #include "MagickCore/draw.h" 53 #include "MagickCore/exception.h" 54 #include "MagickCore/exception-private.h" 55 #include "MagickCore/image.h" 56 #include "MagickCore/image-private.h" 57 #include "MagickCore/list.h" 58 #include "MagickCore/magick.h" 59 #include "MagickCore/memory_.h" 60 #include "MagickCore/paint.h" 61 #include "MagickCore/pixel-accessor.h" 62 #include "MagickCore/quantum-private.h" 63 #include "MagickCore/static.h" 64 #include "MagickCore/string_.h" 65 #include "MagickCore/module.h" 66 #include "MagickCore/studio.h" 67 68 /* 70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 71 % % 72 % % 73 % % 74 % R e a d G R A D I E N T I m a g e % 75 % % 76 % % 77 % % 78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 79 % 80 % ReadGRADIENTImage creates a gradient image and initializes it to 81 % the color range as specified by the filename. It allocates the memory 82 % necessary for the new Image structure and returns a pointer to the new 83 % image. 84 % 85 % The format of the ReadGRADIENTImage method is: 86 % 87 % Image *ReadGRADIENTImage(const ImageInfo *image_info, 88 % ExceptionInfo *exception) 89 % 90 % A description of each parameter follows: 91 % 92 % o image_info: the image info. 93 % 94 % o exception: return any errors or warnings in this structure. 95 % 96 */ 97 static Image *ReadGRADIENTImage(const ImageInfo *image_info, 98 ExceptionInfo *exception) 99 { 100 char 101 colorname[MagickPathExtent+4]; 102 103 Image 104 *image; 105 106 ImageInfo 107 *read_info; 108 109 MagickBooleanType 110 icc_color, 111 status; 112 113 StopInfo 114 *stops; 115 116 /* 117 Initialize Image structure. 118 */ 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 read_info=CloneImageInfo(image_info); 127 SetImageInfoBlob(read_info,(void *) NULL,0); 128 (void) CopyMagickString(colorname,image_info->filename,MagickPathExtent); 129 (void) sscanf(image_info->filename,"%[^-]",colorname); 130 (void) FormatLocaleString(read_info->filename,MagickPathExtent,"xc:%s", 131 colorname); 132 image=ReadImage(read_info,exception); 133 read_info=DestroyImageInfo(read_info); 134 if (image == (Image *) NULL) 135 return((Image *) NULL); 136 (void) SetImageAlpha(image,(Quantum) TransparentAlpha,exception); 137 (void) CopyMagickString(image->filename,image_info->filename,MagickPathExtent); 138 icc_color=MagickFalse; 139 if (LocaleCompare(colorname,"icc") == 0) 140 { 141 (void) ConcatenateMagickString(colorname,"-",MagickPathExtent); 142 (void) sscanf(image_info->filename,"%*[^-]-%[^-]",colorname+4); 143 icc_color=MagickTrue; 144 } 145 stops=(StopInfo *) AcquireQuantumMemory(2,sizeof(*stops)); 146 if (stops == (StopInfo *) NULL) 147 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 148 stops[0].offset=0.0; 149 stops[1].offset=1.0; 150 status=QueryColorCompliance(colorname,AllCompliance,&stops[0].color,exception); 151 if (status == MagickFalse) 152 { 153 stops=(StopInfo *) RelinquishMagickMemory(stops); 154 image=DestroyImage(image); 155 return((Image *) NULL); 156 } 157 (void) SetImageColorspace(image,stops[0].color.colorspace,exception); 158 (void) CopyMagickString(colorname,"white",MagickPathExtent); 159 if (GetPixelInfoIntensity(image,&stops[0].color) > (QuantumRange/2.0)) 160 (void) CopyMagickString(colorname,"black",MagickPathExtent); 161 if (icc_color == MagickFalse) 162 (void) sscanf(image_info->filename,"%*[^-]-%[^-]",colorname); 163 else 164 (void) sscanf(image_info->filename,"%*[^-]-%*[^-]-%[^-]",colorname); 165 status=QueryColorCompliance(colorname,AllCompliance,&stops[1].color,exception); 166 if (status == MagickFalse) 167 { 168 stops=(StopInfo *) RelinquishMagickMemory(stops); 169 image=DestroyImage(image); 170 return((Image *) NULL); 171 } 172 image->alpha_trait=stops[0].color.alpha_trait; 173 if (stops[1].color.alpha_trait != UndefinedPixelTrait) 174 image->alpha_trait=stops[1].color.alpha_trait; 175 status=GradientImage(image,LocaleCompare(image_info->magick,"GRADIENT") == 0 ? 176 LinearGradient : RadialGradient,PadSpread,stops,2,exception); 177 stops=(StopInfo *) RelinquishMagickMemory(stops); 178 if (status == MagickFalse) 179 { 180 image=DestroyImageList(image); 181 return((Image *) NULL); 182 } 183 return(GetFirstImageInList(image)); 184 } 185 186 /* 188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 189 % % 190 % % 191 % % 192 % R e g i s t e r G R A D I E N T I m a g e % 193 % % 194 % % 195 % % 196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 197 % 198 % RegisterGRADIENTImage() adds attributes for the GRADIENT image format 199 % to the list of supported formats. The attributes include the image format 200 % tag, a method to read and/or write the format, whether the format 201 % supports the saving of more than one frame to the same file or blob, 202 % whether the format supports native in-memory I/O, and a brief 203 % description of the format. 204 % 205 % The format of the RegisterGRADIENTImage method is: 206 % 207 % size_t RegisterGRADIENTImage(void) 208 % 209 */ 210 ModuleExport size_t RegisterGRADIENTImage(void) 211 { 212 MagickInfo 213 *entry; 214 215 entry=AcquireMagickInfo("GRADIENT","GRADIENT", 216 "Gradual linear passing from one shade to another"); 217 entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage; 218 entry->flags^=CoderAdjoinFlag; 219 entry->flags|=CoderRawSupportFlag; 220 entry->format_type=ImplicitFormatType; 221 (void) RegisterMagickInfo(entry); 222 entry=AcquireMagickInfo("GRADIENT","RADIAL-GRADIENT", 223 "Gradual radial passing from one shade to another"); 224 entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage; 225 entry->flags^=CoderAdjoinFlag; 226 entry->flags|=CoderRawSupportFlag; 227 entry->format_type=ImplicitFormatType; 228 (void) RegisterMagickInfo(entry); 229 return(MagickImageCoderSignature); 230 } 231 232 /* 234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 235 % % 236 % % 237 % % 238 % U n r e g i s t e r G R A D I E N T I m a g e % 239 % % 240 % % 241 % % 242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 243 % 244 % UnregisterGRADIENTImage() removes format registrations made by the 245 % GRADIENT module from the list of supported formats. 246 % 247 % The format of the UnregisterGRADIENTImage method is: 248 % 249 % UnregisterGRADIENTImage(void) 250 % 251 */ 252 ModuleExport void UnregisterGRADIENTImage(void) 253 { 254 (void) UnregisterMagickInfo("RADIAL-GRADIENT"); 255 (void) UnregisterMagickInfo("GRADIENT"); 256 } 257