2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % PPPP L AAA SSSSS M M AAA %
7 % P P L A A SS MM MM A A %
8 % PPPP L AAAAA SSS M M M AAAAA %
10 % P LLLLL A A SSSSS M M A A %
13 % Read a Plasma Image. %
20 % Copyright 1999-2011 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 % http://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/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/constitute.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/fx.h"
50 #include "MagickCore/image.h"
51 #include "MagickCore/image-private.h"
52 #include "MagickCore/list.h"
53 #include "MagickCore/magick.h"
54 #include "MagickCore/memory_.h"
55 #include "MagickCore/monitor.h"
56 #include "MagickCore/monitor-private.h"
57 #include "MagickCore/pixel-accessor.h"
58 #include "MagickCore/random_.h"
59 #include "MagickCore/random-private.h"
60 #include "MagickCore/signature-private.h"
61 #include "MagickCore/quantum-private.h"
62 #include "MagickCore/static.h"
63 #include "MagickCore/string_.h"
64 #include "MagickCore/module.h"
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 % R e a d P L A S M A I m a g e %
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 % ReadPlasmaImage creates a plasma fractal image. The image is
78 % initialized to the X server color as specified by the filename.
80 % The format of the ReadPlasmaImage method is:
82 % Image *ReadPlasmaImage(const ImageInfo *image_info,
83 % ExceptionInfo *exception)
85 % A description of each parameter follows:
87 % o image_info: the image info.
89 % o exception: return any errors or warnings in this structure.
93 static inline size_t MagickMax(const size_t x,const size_t y)
100 static inline void PlasmaPixel(Image *image,RandomInfo *random_info,double x,
101 double y,ExceptionInfo *exception)
109 q=GetAuthenticPixels(image,(ssize_t) ceil(x-0.5),(ssize_t) ceil(y-0.5),1,1,
111 if (q == (Quantum *) NULL)
113 range=GetQuantumRange(16UL);
114 SetPixelRed(image,ScaleAnyToQuantum((size_t) (65535.0*
115 GetPseudoRandomValue(random_info)+0.5),range),q);
116 SetPixelGreen(image,ScaleAnyToQuantum((size_t) (65535.0*
117 GetPseudoRandomValue(random_info)+0.5),range),q);
118 SetPixelBlue(image,ScaleAnyToQuantum((size_t) (65535.0*
119 GetPseudoRandomValue(random_info)+0.5),range),q);
120 (void) SyncAuthenticPixels(image,exception);
123 static Image *ReadPlasmaImage(const ImageInfo *image_info,
124 ExceptionInfo *exception)
155 Recursively apply plasma to the image.
157 read_info=CloneImageInfo(image_info);
158 SetImageInfoBlob(read_info,(void *) NULL,0);
159 (void) FormatLocaleString(read_info->filename,MaxTextExtent,
160 "gradient:%s",image_info->filename);
161 image=ReadImage(read_info,exception);
162 read_info=DestroyImageInfo(read_info);
163 if (image == (Image *) NULL)
164 return((Image *) NULL);
165 image->storage_class=DirectClass;
166 for (y=0; y < (ssize_t) image->rows; y++)
168 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
169 if (q == (Quantum *) NULL)
171 for (x=0; x < (ssize_t) image->columns; x++)
173 SetPixelAlpha(image,QuantumRange/2,q);
174 q+=GetPixelChannels(image);
176 if (SyncAuthenticPixels(image,exception) == MagickFalse)
181 segment_info.x2=(double) image->columns-1;
182 segment_info.y2=(double) image->rows-1;
183 if (LocaleCompare(image_info->filename,"fractal") == 0)
189 Seed pixels before recursion.
191 random_info=AcquireRandomInfo();
192 PlasmaPixel(image,random_info,segment_info.x1,segment_info.y1,exception);
193 PlasmaPixel(image,random_info,segment_info.x1,(segment_info.y1+
194 segment_info.y2)/2,exception);
195 PlasmaPixel(image,random_info,segment_info.x1,segment_info.y2,exception);
196 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
197 segment_info.y1,exception);
198 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
199 (segment_info.y1+segment_info.y2)/2,exception);
200 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
201 segment_info.y2,exception);
202 PlasmaPixel(image,random_info,segment_info.x2,segment_info.y1,exception);
203 PlasmaPixel(image,random_info,segment_info.x2,(segment_info.y1+
204 segment_info.y2)/2,exception);
205 PlasmaPixel(image,random_info,segment_info.x2,segment_info.y2,exception);
206 random_info=DestroyRandomInfo(random_info);
208 i=(size_t) MagickMax(image->columns,image->rows)/2;
209 for (max_depth=0; i != 0; max_depth++)
211 for (depth=1; ; depth++)
213 if (PlasmaImage(image,&segment_info,0,depth,exception) != MagickFalse)
215 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) depth,
217 if (status == MagickFalse)
220 (void) SetImageAlphaChannel(image,DeactivateAlphaChannel,exception);
221 return(GetFirstImageInList(image));
225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229 % R e g i s t e r P L A S M A I m a g e %
233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235 % RegisterPLASMAImage() adds attributes for the Plasma image format to
236 % the list of supported formats. The attributes include the image format
237 % tag, a method to read and/or write the format, whether the format
238 % supports the saving of more than one frame to the same file or blob,
239 % whether the format supports native in-memory I/O, and a brief
240 % description of the format.
242 % The format of the RegisterPLASMAImage method is:
244 % size_t RegisterPLASMAImage(void)
247 ModuleExport size_t RegisterPLASMAImage(void)
252 entry=SetMagickInfo("PLASMA");
253 entry->decoder=(DecodeImageHandler *) ReadPlasmaImage;
254 entry->adjoin=MagickFalse;
255 entry->format_type=ImplicitFormatType;
256 entry->description=ConstantString("Plasma fractal image");
257 entry->module=ConstantString("PLASMA");
258 (void) RegisterMagickInfo(entry);
259 entry=SetMagickInfo("FRACTAL");
260 entry->decoder=(DecodeImageHandler *) ReadPlasmaImage;
261 entry->adjoin=MagickFalse;
262 entry->format_type=ImplicitFormatType;
263 entry->description=ConstantString("Plasma fractal image");
264 entry->module=ConstantString("PLASMA");
265 (void) RegisterMagickInfo(entry);
266 return(MagickImageCoderSignature);
270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 % U n r e g i s t e r P L A S M A I m a g e %
278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 % UnregisterPLASMAImage() removes format registrations made by the
281 % PLASMA module from the list of supported formats.
283 % The format of the UnregisterPLASMAImage method is:
285 % UnregisterPLASMAImage(void)
288 ModuleExport void UnregisterPLASMAImage(void)
290 (void) UnregisterMagickInfo("FRACTAL");
291 (void) UnregisterMagickInfo("PLASMA");