blob: 3558e97adaa179b91a3b6c02c098d806c67255c8 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
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 %
9% P L A A SS M M A A %
10% P LLLLL A A SSSSS M M A A %
11% %
12% %
13% Read a Plasma Image. %
14% %
15% Software Design %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
Cristy7ce65e72015-12-12 18:03:16 -050020% Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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*/
cristy4c08aed2011-07-01 19:47:50 +000042#include "MagickCore/studio.h"
43#include "MagickCore/blob.h"
44#include "MagickCore/blob-private.h"
45#include "MagickCore/cache.h"
cristy6a2180c2013-05-27 10:28:36 +000046#include "MagickCore/channel.h"
cristy4c08aed2011-07-01 19:47:50 +000047#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"
cristy3ed852e2009-09-05 21:47:34 +000066
67/*
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69% %
70% %
71% %
72% R e a d P L A S M A I m a g e %
73% %
74% %
75% %
76%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77%
78% ReadPlasmaImage creates a plasma fractal image. The image is
79% initialized to the X server color as specified by the filename.
80%
81% The format of the ReadPlasmaImage method is:
82%
83% Image *ReadPlasmaImage(const ImageInfo *image_info,
84% ExceptionInfo *exception)
85%
86% A description of each parameter follows:
87%
88% o image_info: the image info.
89%
90% o exception: return any errors or warnings in this structure.
91%
92*/
93
cristy3ed852e2009-09-05 21:47:34 +000094static inline void PlasmaPixel(Image *image,RandomInfo *random_info,double x,
cristyc82a27b2011-10-21 01:07:16 +000095 double y,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +000096{
cristy4c08aed2011-07-01 19:47:50 +000097 register Quantum
cristy3ed852e2009-09-05 21:47:34 +000098 *q;
99
cristybb503372010-05-27 20:51:26 +0000100 q=GetAuthenticPixels(image,(ssize_t) ceil(x-0.5),(ssize_t) ceil(y-0.5),1,1,
cristy3ed852e2009-09-05 21:47:34 +0000101 exception);
cristyacd2ed22011-08-30 01:44:23 +0000102 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000103 return;
cristy614c65f2013-01-22 23:05:21 +0000104 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (65535.0*
105 GetPseudoRandomValue(random_info)+0.5)),q);
106 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (65535.0*
107 GetPseudoRandomValue(random_info)+0.5)),q);
108 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (65535.0*
109 GetPseudoRandomValue(random_info)+0.5)),q);
cristy3ed852e2009-09-05 21:47:34 +0000110 (void) SyncAuthenticPixels(image,exception);
111}
112
113static Image *ReadPlasmaImage(const ImageInfo *image_info,
114 ExceptionInfo *exception)
115{
116 Image
117 *image;
118
119 ImageInfo
120 *read_info;
121
cristy3ed852e2009-09-05 21:47:34 +0000122 MagickBooleanType
123 status;
124
cristybb503372010-05-27 20:51:26 +0000125 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000126 x;
127
cristy4c08aed2011-07-01 19:47:50 +0000128 register Quantum
cristy3ed852e2009-09-05 21:47:34 +0000129 *q;
130
cristybb503372010-05-27 20:51:26 +0000131 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000132 i;
133
134 SegmentInfo
135 segment_info;
136
cristybb503372010-05-27 20:51:26 +0000137 size_t
cristy3ed852e2009-09-05 21:47:34 +0000138 depth,
139 max_depth;
140
cristyaff6d802011-04-26 01:46:31 +0000141 ssize_t
142 y;
143
cristy3ed852e2009-09-05 21:47:34 +0000144 /*
145 Recursively apply plasma to the image.
146 */
147 read_info=CloneImageInfo(image_info);
148 SetImageInfoBlob(read_info,(void *) NULL,0);
cristy151b66d2015-04-15 10:50:31 +0000149 (void) FormatLocaleString(read_info->filename,MagickPathExtent,
cristy3ed852e2009-09-05 21:47:34 +0000150 "gradient:%s",image_info->filename);
151 image=ReadImage(read_info,exception);
152 read_info=DestroyImageInfo(read_info);
153 if (image == (Image *) NULL)
154 return((Image *) NULL);
cristy9cd32fb2012-06-20 00:59:59 +0000155 (void) SetImageStorageClass(image,DirectClass,exception);
cristybb503372010-05-27 20:51:26 +0000156 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000157 {
158 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000159 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000160 break;
cristybb503372010-05-27 20:51:26 +0000161 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000162 {
cristy4c08aed2011-07-01 19:47:50 +0000163 SetPixelAlpha(image,QuantumRange/2,q);
cristyed231572011-07-14 02:18:59 +0000164 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000165 }
166 if (SyncAuthenticPixels(image,exception) == MagickFalse)
167 break;
168 }
169 segment_info.x1=0;
170 segment_info.y1=0;
171 segment_info.x2=(double) image->columns-1;
172 segment_info.y2=(double) image->rows-1;
173 if (LocaleCompare(image_info->filename,"fractal") == 0)
174 {
175 RandomInfo
176 *random_info;
177
178 /*
179 Seed pixels before recursion.
180 */
cristy9cd32fb2012-06-20 00:59:59 +0000181 (void) SetImageColorspace(image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000182 random_info=AcquireRandomInfo();
cristyc82a27b2011-10-21 01:07:16 +0000183 PlasmaPixel(image,random_info,segment_info.x1,segment_info.y1,exception);
cristy3ed852e2009-09-05 21:47:34 +0000184 PlasmaPixel(image,random_info,segment_info.x1,(segment_info.y1+
cristyc82a27b2011-10-21 01:07:16 +0000185 segment_info.y2)/2,exception);
186 PlasmaPixel(image,random_info,segment_info.x1,segment_info.y2,exception);
cristy3ed852e2009-09-05 21:47:34 +0000187 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
cristyc82a27b2011-10-21 01:07:16 +0000188 segment_info.y1,exception);
cristy3ed852e2009-09-05 21:47:34 +0000189 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
cristyc82a27b2011-10-21 01:07:16 +0000190 (segment_info.y1+segment_info.y2)/2,exception);
cristy3ed852e2009-09-05 21:47:34 +0000191 PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
cristyc82a27b2011-10-21 01:07:16 +0000192 segment_info.y2,exception);
193 PlasmaPixel(image,random_info,segment_info.x2,segment_info.y1,exception);
cristy3ed852e2009-09-05 21:47:34 +0000194 PlasmaPixel(image,random_info,segment_info.x2,(segment_info.y1+
cristyc82a27b2011-10-21 01:07:16 +0000195 segment_info.y2)/2,exception);
196 PlasmaPixel(image,random_info,segment_info.x2,segment_info.y2,exception);
cristy3ed852e2009-09-05 21:47:34 +0000197 random_info=DestroyRandomInfo(random_info);
198 }
cristybb503372010-05-27 20:51:26 +0000199 i=(size_t) MagickMax(image->columns,image->rows)/2;
cristy3ed852e2009-09-05 21:47:34 +0000200 for (max_depth=0; i != 0; max_depth++)
201 i>>=1;
202 for (depth=1; ; depth++)
203 {
cristy5cbc0162011-08-29 00:36:28 +0000204 if (PlasmaImage(image,&segment_info,0,depth,exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000205 break;
206 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) depth,
207 max_depth);
208 if (status == MagickFalse)
209 break;
210 }
cristy3ed852e2009-09-05 21:47:34 +0000211 return(GetFirstImageInList(image));
212}
213
214/*
215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216% %
217% %
218% %
219% R e g i s t e r P L A S M A I m a g e %
220% %
221% %
222% %
223%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224%
225% RegisterPLASMAImage() adds attributes for the Plasma image format to
226% the list of supported formats. The attributes include the image format
227% tag, a method to read and/or write the format, whether the format
228% supports the saving of more than one frame to the same file or blob,
229% whether the format supports native in-memory I/O, and a brief
230% description of the format.
231%
232% The format of the RegisterPLASMAImage method is:
233%
cristybb503372010-05-27 20:51:26 +0000234% size_t RegisterPLASMAImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000235%
236*/
cristybb503372010-05-27 20:51:26 +0000237ModuleExport size_t RegisterPLASMAImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000238{
239 MagickInfo
240 *entry;
241
dirk06b627a2015-04-06 18:59:17 +0000242 entry=AcquireMagickInfo("PLASMA","PLASMA","Plasma fractal image");
cristy3ed852e2009-09-05 21:47:34 +0000243 entry->decoder=(DecodeImageHandler *) ReadPlasmaImage;
dirk08e9a112015-02-22 01:51:41 +0000244 entry->flags^=CoderAdjoinFlag;
cristy009d7392010-07-25 22:08:41 +0000245 entry->format_type=ImplicitFormatType;
cristy3ed852e2009-09-05 21:47:34 +0000246 (void) RegisterMagickInfo(entry);
dirk06b627a2015-04-06 18:59:17 +0000247 entry=AcquireMagickInfo("PLASMA","FRACTAL","Plasma fractal image");
cristy3ed852e2009-09-05 21:47:34 +0000248 entry->decoder=(DecodeImageHandler *) ReadPlasmaImage;
dirk08e9a112015-02-22 01:51:41 +0000249 entry->flags^=CoderAdjoinFlag;
cristy009d7392010-07-25 22:08:41 +0000250 entry->format_type=ImplicitFormatType;
cristy3ed852e2009-09-05 21:47:34 +0000251 (void) RegisterMagickInfo(entry);
252 return(MagickImageCoderSignature);
253}
254
255/*
256%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257% %
258% %
259% %
260% U n r e g i s t e r P L A S M A I m a g e %
261% %
262% %
263% %
264%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265%
266% UnregisterPLASMAImage() removes format registrations made by the
267% PLASMA module from the list of supported formats.
268%
269% The format of the UnregisterPLASMAImage method is:
270%
271% UnregisterPLASMAImage(void)
272%
273*/
274ModuleExport void UnregisterPLASMAImage(void)
275{
276 (void) UnregisterMagickInfo("FRACTAL");
277 (void) UnregisterMagickInfo("PLASMA");
278}