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-2010 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 "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/cache.h"
46 #include "magick/constitute.h"
47 #include "magick/exception.h"
48 #include "magick/exception-private.h"
49 #include "magick/fx.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/monitor.h"
56 #include "magick/monitor-private.h"
57 #include "magick/random_.h"
58 #include "magick/random-private.h"
59 #include "magick/signature-private.h"
60 #include "magick/quantum-private.h"
61 #include "magick/static.h"
62 #include "magick/string_.h"
63 #include "magick/module.h"
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 % R e a d P L A S M A I m a g e %
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 % ReadPlasmaImage creates a plasma fractal image. The image is
77 % initialized to the X server color as specified by the filename.
79 % The format of the ReadPlasmaImage method is:
81 % Image *ReadPlasmaImage(const ImageInfo *image_info,
82 % ExceptionInfo *exception)
84 % A description of each parameter follows:
86 % o image_info: the image info.
88 % o exception: return any errors or warnings in this structure.
92 static inline size_t MagickMax(const size_t x,const size_t y)
99 static inline void PlasmaPixel(Image *image,RandomInfo *random_info,double x,
111 exception=(&image->exception);
112 q=GetAuthenticPixels(image,(ssize_t) ceil(x-0.5),(ssize_t) ceil(y-0.5),1,1,
114 if (q == (PixelPacket *) NULL)
116 range=GetQuantumRange(16UL);
117 q->red=ScaleAnyToQuantum((size_t) (65535.0*
118 GetPseudoRandomValue(random_info)+0.5),range);
119 q->green=ScaleAnyToQuantum((size_t) (65535.0*
120 GetPseudoRandomValue(random_info)+0.5),range);
121 q->blue=ScaleAnyToQuantum((size_t) (65535.0*
122 GetPseudoRandomValue(random_info)+0.5),range);
123 (void) SyncAuthenticPixels(image,exception);
126 static Image *ReadPlasmaImage(const ImageInfo *image_info,
127 ExceptionInfo *exception)
158 Recursively apply plasma to the image.
160 read_info=CloneImageInfo(image_info);
161 SetImageInfoBlob(read_info,(void *) NULL,0);
162 (void) FormatMagickString(read_info->filename,MaxTextExtent,
163 "gradient:%s",image_info->filename);
164 image=ReadImage(read_info,exception);
165 read_info=DestroyImageInfo(read_info);
166 if (image == (Image *) NULL)
167 return((Image *) NULL);
168 image->storage_class=DirectClass;
169 for (y=0; y < (ssize_t) image->rows; y++)
171 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
172 if (q == (PixelPacket *) NULL)
174 for (x=0; x < (ssize_t) image->columns; x++)
176 q->opacity=(Quantum) (QuantumRange/2);
179 if (SyncAuthenticPixels(image,exception) == MagickFalse)
184 segment_info.x2=(double) image->columns-1;
185 segment_info.y2=(double) image->rows-1;
186 if (LocaleCompare(image_info->filename,"fractal") == 0)
192 Seed pixels before recursion.
194 random_info=AcquireRandomInfo();
195 PlasmaPixel(image,random_info,segment_info.x1,segment_info.y1);
196 PlasmaPixel(image,random_info,segment_info.x1,(segment_info.y1+
198 PlasmaPixel(image,random_info,segment_info.x1,segment_info.y2);
199 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
201 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
202 (segment_info.y1+segment_info.y2)/2);
203 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
205 PlasmaPixel(image,random_info,segment_info.x2,segment_info.y1);
206 PlasmaPixel(image,random_info,segment_info.x2,(segment_info.y1+
208 PlasmaPixel(image,random_info,segment_info.x2,segment_info.y2);
209 random_info=DestroyRandomInfo(random_info);
211 i=(size_t) MagickMax(image->columns,image->rows)/2;
212 for (max_depth=0; i != 0; max_depth++)
214 for (depth=1; ; depth++)
216 if (PlasmaImage(image,&segment_info,0,depth) != MagickFalse)
218 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) depth,
220 if (status == MagickFalse)
223 (void) SetImageAlphaChannel(image,DeactivateAlphaChannel);
224 return(GetFirstImageInList(image));
228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 % R e g i s t e r P L A S M A I m a g e %
236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 % RegisterPLASMAImage() adds attributes for the Plasma image format to
239 % the list of supported formats. The attributes include the image format
240 % tag, a method to read and/or write the format, whether the format
241 % supports the saving of more than one frame to the same file or blob,
242 % whether the format supports native in-memory I/O, and a brief
243 % description of the format.
245 % The format of the RegisterPLASMAImage method is:
247 % size_t RegisterPLASMAImage(void)
250 ModuleExport size_t RegisterPLASMAImage(void)
255 entry=SetMagickInfo("PLASMA");
256 entry->decoder=(DecodeImageHandler *) ReadPlasmaImage;
257 entry->adjoin=MagickFalse;
258 entry->format_type=ImplicitFormatType;
259 entry->description=ConstantString("Plasma fractal image");
260 entry->module=ConstantString("PLASMA");
261 (void) RegisterMagickInfo(entry);
262 entry=SetMagickInfo("FRACTAL");
263 entry->decoder=(DecodeImageHandler *) ReadPlasmaImage;
264 entry->adjoin=MagickFalse;
265 entry->format_type=ImplicitFormatType;
266 entry->description=ConstantString("Plasma fractal image");
267 entry->module=ConstantString("PLASMA");
268 (void) RegisterMagickInfo(entry);
269 return(MagickImageCoderSignature);
273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 % U n r e g i s t e r P L A S M A I m a g e %
281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
283 % UnregisterPLASMAImage() removes format registrations made by the
284 % PLASMA module from the list of supported formats.
286 % The format of the UnregisterPLASMAImage method is:
288 % UnregisterPLASMAImage(void)
291 ModuleExport void UnregisterPLASMAImage(void)
293 (void) UnregisterMagickInfo("FRACTAL");
294 (void) UnregisterMagickInfo("PLASMA");