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-2014 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/channel.h"
47 #include "MagickCore/constitute.h"
48 #include "MagickCore/exception.h"
49 #include "MagickCore/exception-private.h"
50 #include "MagickCore/fx.h"
51 #include "MagickCore/image.h"
52 #include "MagickCore/image-private.h"
53 #include "MagickCore/list.h"
54 #include "MagickCore/magick.h"
55 #include "MagickCore/memory_.h"
56 #include "MagickCore/monitor.h"
57 #include "MagickCore/monitor-private.h"
58 #include "MagickCore/pixel-accessor.h"
59 #include "MagickCore/random_.h"
60 #include "MagickCore/random-private.h"
61 #include "MagickCore/signature-private.h"
62 #include "MagickCore/quantum-private.h"
63 #include "MagickCore/static.h"
64 #include "MagickCore/string_.h"
65 #include "MagickCore/module.h"
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 % R e a d P L A S M A I m a g e %
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 % ReadPlasmaImage creates a plasma fractal image. The image is
79 % initialized to the X server color as specified by the filename.
81 % The format of the ReadPlasmaImage method is:
83 % Image *ReadPlasmaImage(const ImageInfo *image_info,
84 % ExceptionInfo *exception)
86 % A description of each parameter follows:
88 % o image_info: the image info.
90 % o exception: return any errors or warnings in this structure.
94 static inline size_t MagickMax(const size_t x,const size_t y)
101 static inline void PlasmaPixel(Image *image,RandomInfo *random_info,double x,
102 double y,ExceptionInfo *exception)
107 q=GetAuthenticPixels(image,(ssize_t) ceil(x-0.5),(ssize_t) ceil(y-0.5),1,1,
109 if (q == (Quantum *) NULL)
111 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (65535.0*
112 GetPseudoRandomValue(random_info)+0.5)),q);
113 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (65535.0*
114 GetPseudoRandomValue(random_info)+0.5)),q);
115 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (65535.0*
116 GetPseudoRandomValue(random_info)+0.5)),q);
117 (void) SyncAuthenticPixels(image,exception);
120 static Image *ReadPlasmaImage(const ImageInfo *image_info,
121 ExceptionInfo *exception)
152 Recursively apply plasma to the image.
154 read_info=CloneImageInfo(image_info);
155 SetImageInfoBlob(read_info,(void *) NULL,0);
156 (void) FormatLocaleString(read_info->filename,MaxTextExtent,
157 "gradient:%s",image_info->filename);
158 image=ReadImage(read_info,exception);
159 read_info=DestroyImageInfo(read_info);
160 if (image == (Image *) NULL)
161 return((Image *) NULL);
162 (void) SetImageStorageClass(image,DirectClass,exception);
163 for (y=0; y < (ssize_t) image->rows; y++)
165 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
166 if (q == (Quantum *) NULL)
168 for (x=0; x < (ssize_t) image->columns; x++)
170 SetPixelAlpha(image,QuantumRange/2,q);
171 q+=GetPixelChannels(image);
173 if (SyncAuthenticPixels(image,exception) == MagickFalse)
178 segment_info.x2=(double) image->columns-1;
179 segment_info.y2=(double) image->rows-1;
180 if (LocaleCompare(image_info->filename,"fractal") == 0)
186 Seed pixels before recursion.
188 (void) SetImageColorspace(image,sRGBColorspace,exception);
189 random_info=AcquireRandomInfo();
190 PlasmaPixel(image,random_info,segment_info.x1,segment_info.y1,exception);
191 PlasmaPixel(image,random_info,segment_info.x1,(segment_info.y1+
192 segment_info.y2)/2,exception);
193 PlasmaPixel(image,random_info,segment_info.x1,segment_info.y2,exception);
194 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
195 segment_info.y1,exception);
196 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
197 (segment_info.y1+segment_info.y2)/2,exception);
198 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
199 segment_info.y2,exception);
200 PlasmaPixel(image,random_info,segment_info.x2,segment_info.y1,exception);
201 PlasmaPixel(image,random_info,segment_info.x2,(segment_info.y1+
202 segment_info.y2)/2,exception);
203 PlasmaPixel(image,random_info,segment_info.x2,segment_info.y2,exception);
204 random_info=DestroyRandomInfo(random_info);
206 i=(size_t) MagickMax(image->columns,image->rows)/2;
207 for (max_depth=0; i != 0; max_depth++)
209 for (depth=1; ; depth++)
211 if (PlasmaImage(image,&segment_info,0,depth,exception) != MagickFalse)
213 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) depth,
215 if (status == MagickFalse)
218 return(GetFirstImageInList(image));
222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 % R e g i s t e r P L A S M A I m a g e %
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 % RegisterPLASMAImage() adds attributes for the Plasma image format to
233 % the list of supported formats. The attributes include the image format
234 % tag, a method to read and/or write the format, whether the format
235 % supports the saving of more than one frame to the same file or blob,
236 % whether the format supports native in-memory I/O, and a brief
237 % description of the format.
239 % The format of the RegisterPLASMAImage method is:
241 % size_t RegisterPLASMAImage(void)
244 ModuleExport size_t RegisterPLASMAImage(void)
249 entry=SetMagickInfo("PLASMA");
250 entry->decoder=(DecodeImageHandler *) ReadPlasmaImage;
251 entry->adjoin=MagickFalse;
252 entry->format_type=ImplicitFormatType;
253 entry->description=ConstantString("Plasma fractal image");
254 entry->module=ConstantString("PLASMA");
255 (void) RegisterMagickInfo(entry);
256 entry=SetMagickInfo("FRACTAL");
257 entry->decoder=(DecodeImageHandler *) ReadPlasmaImage;
258 entry->adjoin=MagickFalse;
259 entry->format_type=ImplicitFormatType;
260 entry->description=ConstantString("Plasma fractal image");
261 entry->module=ConstantString("PLASMA");
262 (void) RegisterMagickInfo(entry);
263 return(MagickImageCoderSignature);
267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 % U n r e g i s t e r P L A S M A I m a g e %
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 % UnregisterPLASMAImage() removes format registrations made by the
278 % PLASMA module from the list of supported formats.
280 % The format of the UnregisterPLASMAImage method is:
282 % UnregisterPLASMAImage(void)
285 ModuleExport void UnregisterPLASMAImage(void)
287 (void) UnregisterMagickInfo("FRACTAL");
288 (void) UnregisterMagickInfo("PLASMA");