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 % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 16af1cb | 2009-12-11 21:38:29 +0000 | [diff] [blame] | 20 | % Copyright 1999-2010 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 | */ |
| 42 | #include "magick/studio.h" |
| 43 | #include "magick/blob.h" |
| 44 | #include "magick/blob-private.h" |
| 45 | #include "magick/color.h" |
| 46 | #include "magick/color-private.h" |
| 47 | #include "magick/draw.h" |
| 48 | #include "magick/exception.h" |
| 49 | #include "magick/exception-private.h" |
| 50 | #include "magick/image.h" |
| 51 | #include "magick/image-private.h" |
| 52 | #include "magick/list.h" |
| 53 | #include "magick/magick.h" |
| 54 | #include "magick/memory_.h" |
| 55 | #include "magick/paint.h" |
| 56 | #include "magick/pixel-private.h" |
| 57 | #include "magick/quantum-private.h" |
| 58 | #include "magick/static.h" |
| 59 | #include "magick/string_.h" |
| 60 | #include "magick/module.h" |
| 61 | #include "magick/studio.h" |
| 62 | |
| 63 | /* |
| 64 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 65 | % % |
| 66 | % % |
| 67 | % % |
| 68 | % R e a d G R A D I E N T I m a g e % |
| 69 | % % |
| 70 | % % |
| 71 | % % |
| 72 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 73 | % |
| 74 | % ReadGRADIENTImage creates a gradient image and initializes it to |
| 75 | % the color range as specified by the filename. It allocates the memory |
| 76 | % necessary for the new Image structure and returns a pointer to the new |
| 77 | % image. |
| 78 | % |
| 79 | % The format of the ReadGRADIENTImage method is: |
| 80 | % |
| 81 | % Image *ReadGRADIENTImage(const ImageInfo *image_info, |
| 82 | % ExceptionInfo *exception) |
| 83 | % |
| 84 | % A description of each parameter follows: |
| 85 | % |
| 86 | % o image_info: the image info. |
| 87 | % |
| 88 | % o exception: return any errors or warnings in this structure. |
| 89 | % |
| 90 | */ |
| 91 | static Image *ReadGRADIENTImage(const ImageInfo *image_info, |
| 92 | ExceptionInfo *exception) |
| 93 | { |
| 94 | char |
| 95 | colorname[MaxTextExtent]; |
| 96 | |
| 97 | PixelPacket |
| 98 | start_color, |
| 99 | stop_color; |
| 100 | |
| 101 | Image |
| 102 | *image; |
| 103 | |
| 104 | /* |
| 105 | Initialize Image structure. |
| 106 | */ |
| 107 | assert(image_info != (const ImageInfo *) NULL); |
| 108 | assert(image_info->signature == MagickSignature); |
| 109 | if (image_info->debug != MagickFalse) |
| 110 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 111 | image_info->filename); |
| 112 | assert(exception != (ExceptionInfo *) NULL); |
| 113 | assert(exception->signature == MagickSignature); |
| 114 | image=AcquireImage(image_info); |
| 115 | if ((image->columns == 0) || (image->rows == 0)) |
| 116 | ThrowReaderException(OptionError,"MustSpecifyImageSize"); |
| 117 | (void) SetImageOpacity(image,(Quantum) TransparentOpacity); |
| 118 | (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent); |
| 119 | (void) CopyMagickString(colorname,image_info->filename,MaxTextExtent); |
| 120 | (void) sscanf(image_info->filename,"%[^-]",colorname); |
| 121 | if (QueryColorDatabase(colorname,&start_color,exception) == MagickFalse) |
| 122 | { |
| 123 | image=DestroyImage(image); |
| 124 | return((Image *) NULL); |
| 125 | } |
| 126 | (void) CopyMagickString(colorname,"white",MaxTextExtent); |
| 127 | if (PixelIntensityToQuantum(&start_color) > (Quantum) (QuantumRange/2)) |
| 128 | (void) CopyMagickString(colorname,"black",MaxTextExtent); |
| 129 | (void) sscanf(image_info->filename,"%*[^-]-%s",colorname); |
| 130 | if (QueryColorDatabase(colorname,&stop_color,exception) == MagickFalse) |
| 131 | { |
| 132 | image=DestroyImage(image); |
| 133 | return((Image *) NULL); |
| 134 | } |
| 135 | (void) GradientImage(image,LocaleCompare(image_info->magick,"GRADIENT") == 0 ? |
| 136 | LinearGradient : RadialGradient,PadSpread,&start_color,&stop_color); |
| 137 | return(GetFirstImageInList(image)); |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 142 | % % |
| 143 | % % |
| 144 | % % |
| 145 | % R e g i s t e r G R A D I E N T I m a g e % |
| 146 | % % |
| 147 | % % |
| 148 | % % |
| 149 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 150 | % |
| 151 | % RegisterGRADIENTImage() adds attributes for the GRADIENT image format |
| 152 | % to the list of supported formats. The attributes include the image format |
| 153 | % tag, a method to read and/or write the format, whether the format |
| 154 | % supports the saving of more than one frame to the same file or blob, |
| 155 | % whether the format supports native in-memory I/O, and a brief |
| 156 | % description of the format. |
| 157 | % |
| 158 | % The format of the RegisterGRADIENTImage method is: |
| 159 | % |
| 160 | % unsigned long RegisterGRADIENTImage(void) |
| 161 | % |
| 162 | */ |
| 163 | ModuleExport unsigned long RegisterGRADIENTImage(void) |
| 164 | { |
| 165 | MagickInfo |
| 166 | *entry; |
| 167 | |
| 168 | entry=SetMagickInfo("GRADIENT"); |
| 169 | entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage; |
| 170 | entry->adjoin=MagickFalse; |
| 171 | entry->raw=MagickTrue; |
| 172 | entry->format_type=ExplicitFormatType; |
| 173 | entry->description=ConstantString("Gradual linear passing from one shade to " |
| 174 | "another"); |
| 175 | entry->module=ConstantString("GRADIENT"); |
| 176 | (void) RegisterMagickInfo(entry); |
| 177 | entry=SetMagickInfo("RADIAL-GRADIENT"); |
| 178 | entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage; |
| 179 | entry->adjoin=MagickFalse; |
| 180 | entry->raw=MagickTrue; |
| 181 | entry->format_type=ExplicitFormatType; |
| 182 | entry->description=ConstantString("Gradual radial passing from one shade to " |
| 183 | "another"); |
| 184 | entry->module=ConstantString("GRADIENT"); |
| 185 | (void) RegisterMagickInfo(entry); |
| 186 | return(MagickImageCoderSignature); |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 191 | % % |
| 192 | % % |
| 193 | % % |
| 194 | % U n r e g i s t e r G R A D I E N T I m a g e % |
| 195 | % % |
| 196 | % % |
| 197 | % % |
| 198 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 199 | % |
| 200 | % UnregisterGRADIENTImage() removes format registrations made by the |
| 201 | % GRADIENT module from the list of supported formats. |
| 202 | % |
| 203 | % The format of the UnregisterGRADIENTImage method is: |
| 204 | % |
| 205 | % UnregisterGRADIENTImage(void) |
| 206 | % |
| 207 | */ |
| 208 | ModuleExport void UnregisterGRADIENTImage(void) |
| 209 | { |
| 210 | (void) UnregisterMagickInfo("RADIAL-GRADIENT"); |
| 211 | (void) UnregisterMagickInfo("GRADIENT"); |
| 212 | } |