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-2013 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)
106 q=GetAuthenticPixels(image,(ssize_t) ceil(x-0.5),(ssize_t) ceil(y-0.5),1,1,
108 if (q == (Quantum *) NULL)
110 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (65535.0*
111 GetPseudoRandomValue(random_info)+0.5)),q);
112 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (65535.0*
113 GetPseudoRandomValue(random_info)+0.5)),q);
114 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (65535.0*
115 GetPseudoRandomValue(random_info)+0.5)),q);
116 (void) SyncAuthenticPixels(image,exception);
119 static Image *ReadPlasmaImage(const ImageInfo *image_info,
120 ExceptionInfo *exception)
151 Recursively apply plasma to the image.
153 read_info=CloneImageInfo(image_info);
154 SetImageInfoBlob(read_info,(void *) NULL,0);
155 (void) FormatLocaleString(read_info->filename,MaxTextExtent,
156 "gradient:%s",image_info->filename);
157 image=ReadImage(read_info,exception);
158 read_info=DestroyImageInfo(read_info);
159 if (image == (Image *) NULL)
160 return((Image *) NULL);
161 (void) SetImageStorageClass(image,DirectClass,exception);
162 for (y=0; y < (ssize_t) image->rows; y++)
164 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
165 if (q == (Quantum *) NULL)
167 for (x=0; x < (ssize_t) image->columns; x++)
169 SetPixelAlpha(image,QuantumRange/2,q);
170 q+=GetPixelChannels(image);
172 if (SyncAuthenticPixels(image,exception) == MagickFalse)
177 segment_info.x2=(double) image->columns-1;
178 segment_info.y2=(double) image->rows-1;
179 if (LocaleCompare(image_info->filename,"fractal") == 0)
185 Seed pixels before recursion.
187 (void) SetImageColorspace(image,sRGBColorspace,exception);
188 random_info=AcquireRandomInfo();
189 PlasmaPixel(image,random_info,segment_info.x1,segment_info.y1,exception);
190 PlasmaPixel(image,random_info,segment_info.x1,(segment_info.y1+
191 segment_info.y2)/2,exception);
192 PlasmaPixel(image,random_info,segment_info.x1,segment_info.y2,exception);
193 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
194 segment_info.y1,exception);
195 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
196 (segment_info.y1+segment_info.y2)/2,exception);
197 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
198 segment_info.y2,exception);
199 PlasmaPixel(image,random_info,segment_info.x2,segment_info.y1,exception);
200 PlasmaPixel(image,random_info,segment_info.x2,(segment_info.y1+
201 segment_info.y2)/2,exception);
202 PlasmaPixel(image,random_info,segment_info.x2,segment_info.y2,exception);
203 random_info=DestroyRandomInfo(random_info);
205 i=(size_t) MagickMax(image->columns,image->rows)/2;
206 for (max_depth=0; i != 0; max_depth++)
208 for (depth=1; ; depth++)
210 if (PlasmaImage(image,&segment_info,0,depth,exception) != MagickFalse)
212 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) depth,
214 if (status == MagickFalse)
217 (void) SetImageAlphaChannel(image,SetAlphaChannel,exception);
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");