1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %               V   V  EEEEE  RRRR   SSSSS  IIIII   OOO   N   N               %
7 %               V   V  E      R   R  SS       I    O   O  NN  N               %
8 %               V   V  EEE    RRRR    SSS     I    O   O  N N N               %
9 %                V V   E      R R       SS    I    O   O  N  NN               %
10 %                 V    EEEEE  R  R   SSSSS  IIIII   OOO   N   N               %
11 %                                                                             %
12 %                                                                             %
13 %                   MagickCore Version and Copyright Methods                  %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                   Cristy                                    %
17 %                               September 2002                                %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization      %
21 %  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 #include "MagickCore/studio.h"
40 #include "MagickCore/configure.h"
41 #include "MagickCore/exception.h"
42 #include "MagickCore/exception-private.h"
43 #include "MagickCore/linked-list.h"
44 #include "MagickCore/locale_.h"
45 #include "MagickCore/option.h"
46 #include "MagickCore/string_.h"
47 #include "MagickCore/utility.h"
48 #include "MagickCore/utility-private.h"
49 #include "MagickCore/version.h"
50 #include "MagickCore/version-private.h"
51 
52 /*
53   Define declarations.
54 */
55 #define MagickURLFilename  "index.html"
56 
57 /*
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %                                                                             %
60 %                                                                             %
61 %                                                                             %
62 %   G e t M a g i c k C o p y r i g h t                                       %
63 %                                                                             %
64 %                                                                             %
65 %                                                                             %
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 %
68 %  GetMagickCopyright() returns the ImageMagick API copyright as a string.
69 %
70 %  The format of the GetMagickCopyright method is:
71 %
72 %      const char *GetMagickCopyright(void)
73 %
74 */
GetMagickCopyright(void)75 MagickExport const char *GetMagickCopyright(void)
76 {
77   return(MagickCopyright);
78 }
79 
80 /*
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 %                                                                             %
83 %                                                                             %
84 %                                                                             %
85 %   G e t M a g i c k D e l e g a t e s                                       %
86 %                                                                             %
87 %                                                                             %
88 %                                                                             %
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 %
91 %  GetMagickDelegates() returns the ImageMagick delegate libraries.
92 %
93 %  The format of the GetMagickDelegates method is:
94 %
95 %      const char *GetMagickDelegates(void)
96 %
97 %  No parameters are required.
98 %
99 */
GetMagickDelegates(void)100 MagickExport const char *GetMagickDelegates(void)
101 {
102   return ""
103 #if defined(MAGICKCORE_AUTOTRACE_DELEGATE)
104   "autotrace "
105 #endif
106 #if defined(MAGICKCORE_BZLIB_DELEGATE)
107   "bzlib "
108 #endif
109 #if defined(MAGICKCORE_CAIRO_DELEGATE)
110   "cairo "
111 #endif
112 #if defined(MAGICKCORE_DJVU_DELEGATE)
113   "djvu "
114 #endif
115 #if defined(MAGICKCORE_DPS_DELEGATE)
116   "dps "
117 #endif
118 #if defined(MAGICKCORE_EMF_DELEGATE)
119   "emf "
120 #endif
121 #if defined(MAGICKCORE_FFTW_DELEGATE)
122   "fftw "
123 #endif
124 #if defined(MAGICKCORE_FLIF_DELEGATE)
125   "flif "
126 #endif
127 #if defined(MAGICKCORE_FONTCONFIG_DELEGATE)
128   "fontconfig "
129 #endif
130 #if defined(MAGICKCORE_FPX_DELEGATE)
131   "fpx "
132 #endif
133 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
134   "freetype "
135 #endif
136 #if defined(MAGICKCORE_GS_DELEGATE)
137   "gslib "
138 #endif
139 #if defined(MAGICKCORE_GVC_DELEGATE)
140   "gvc "
141 #endif
142 #if defined(MAGICKCORE_JBIG_DELEGATE)
143   "jbig "
144 #endif
145 #if defined(MAGICKCORE_JPEG_DELEGATE) && defined(MAGICKCORE_PNG_DELEGATE)
146   "jng "
147 #endif
148 #if defined(MAGICKCORE_LIBOPENJP2_DELEGATE)
149   "jp2 "
150 #endif
151 #if defined(MAGICKCORE_JPEG_DELEGATE)
152   "jpeg "
153 #endif
154 #if defined(MAGICKCORE_LCMS_DELEGATE)
155   "lcms "
156 #endif
157 #if defined(MAGICKCORE_LQR_DELEGATE)
158   "lqr "
159 #endif
160 #if defined(MAGICKCORE_LTDL_DELEGATE)
161   "ltdl "
162 #endif
163 #if defined(MAGICKCORE_LZMA_DELEGATE)
164   "lzma "
165 #endif
166 #if defined(MAGICKCORE_OPENEXR_DELEGATE)
167   "openexr "
168 #endif
169 #if defined(MAGICKCORE_PANGOCAIRO_DELEGATE)
170   "pangocairo "
171 #endif
172 #if defined(MAGICKCORE_PNG_DELEGATE)
173   "png "
174 #endif
175 #if defined(MAGICKCORE_DPS_DELEGATE) || defined(MAGICKCORE_GS_DELEGATE) || defined(WIN32)
176   "ps "
177 #endif
178 #if defined(MAGICKCORE_RSVG_DELEGATE)
179   "rsvg "
180 #endif
181 #if defined(MAGICKCORE_TIFF_DELEGATE)
182   "tiff "
183 #endif
184 #if defined(MAGICKCORE_WEBP_DELEGATE)
185   "webp "
186 #endif
187 #if defined(MAGICKCORE_WMF_DELEGATE) || defined (MAGICKCORE_WMFLITE_DELEGATE)
188   "wmf "
189 #endif
190 #if defined(MAGICKCORE_X11_DELEGATE)
191   "x "
192 #endif
193 #if defined(MAGICKCORE_XML_DELEGATE)
194   "xml "
195 #endif
196 #if defined(MAGICKCORE_ZLIB_DELEGATE)
197   "zlib"
198 #endif
199   ;
200 }
201 
202 /*
203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 %                                                                             %
205 %                                                                             %
206 %                                                                             %
207 %   G e t M a g i c k F e a t u r e s                                         %
208 %                                                                             %
209 %                                                                             %
210 %                                                                             %
211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 %
213 %  GetMagickFeatures() returns the ImageMagick features.
214 %
215 %  The format of the GetMagickFeatures method is:
216 %
217 %      const char *GetMagickFeatures(void)
218 %
219 %  No parameters are required.
220 %
221 */
GetMagickFeatures(void)222 MagickExport const char *GetMagickFeatures(void)
223 {
224   return ""
225 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && defined(_DEBUG)
226   "Debug "
227 #endif
228 #if defined(MAGICKCORE_CIPHER_SUPPORT)
229   "Cipher "
230 #endif
231 #if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(MAGICKCORE_HAVE_SOCKET) && defined(MAGICKCORE_THREAD_SUPPORT)
232   "DPC "
233 #endif
234 #if defined(MAGICKCORE_HDRI_SUPPORT)
235   "HDRI "
236 #endif
237 #if defined(MAGICKCORE_BUILD_MODULES) || defined(_DLL)
238   "Modules "
239 #endif
240 #if defined(MAGICKCORE_OPENCL_SUPPORT)
241   "OpenCL "
242 #endif
243 #if defined(MAGICKCORE_OPENMP_SUPPORT)
244   "OpenMP "
245 #endif
246 #if defined(ZERO_CONFIGURATION_SUPPORT)
247   "Zero-configuration "
248 #endif
249   ;
250 }
251 
252 /*
253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254 %                                                                             %
255 %                                                                             %
256 %                                                                             %
257 %   G e t M a g i c k H o m e U R L                                           %
258 %                                                                             %
259 %                                                                             %
260 %                                                                             %
261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 %
263 %  GetMagickHomeURL() returns the ImageMagick home URL.
264 %
265 %  The format of the GetMagickHomeURL method is:
266 %
267 %      char *GetMagickHomeURL(void)
268 %
269 */
GetMagickHomeURL(void)270 MagickExport char *GetMagickHomeURL(void)
271 {
272   char
273     path[MagickPathExtent];
274 
275   const char
276     *element;
277 
278   ExceptionInfo
279     *exception;
280 
281   LinkedListInfo
282     *paths;
283 
284   exception=AcquireExceptionInfo();
285   paths=GetConfigurePaths(MagickURLFilename,exception);
286   exception=DestroyExceptionInfo(exception);
287   if (paths == (LinkedListInfo *) NULL)
288     return(ConstantString(MagickHomeURL));
289   element=(const char *) GetNextValueInLinkedList(paths);
290   while (element != (const char *) NULL)
291   {
292     (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",element,
293       DirectorySeparator,MagickURLFilename);
294     if (IsPathAccessible(path) != MagickFalse)
295       return(ConstantString(path));
296     element=(const char *) GetNextValueInLinkedList(paths);
297   }
298   return(ConstantString(MagickHomeURL));
299 }
300 
301 /*
302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 %                                                                             %
304 %                                                                             %
305 %                                                                             %
306 %   G e t M a g i c k L i c e n s e                                           %
307 %                                                                             %
308 %                                                                             %
309 %                                                                             %
310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 %
312 %  GetMagickLicense() returns the ImageMagick API license as a string.
313 %
314 %  The format of the GetMagickLicense method is:
315 %
316 %      const char *GetMagickLicense(void)
317 %
318 */
GetMagickLicense(void)319 MagickExport const char *GetMagickLicense(void)
320 {
321   return(MagickAuthoritativeLicense);
322 }
323 
324 /*
325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
326 %                                                                             %
327 %                                                                             %
328 %                                                                             %
329 %   G e t M a g i c k P a c k a g e N a m e                                   %
330 %                                                                             %
331 %                                                                             %
332 %                                                                             %
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 %
335 %  GetMagickPackageName() returns the ImageMagick package name.
336 %
337 %  The format of the GetMagickName method is:
338 %
339 %      const char *GetMagickName(void)
340 %
341 %  No parameters are required.
342 %
343 */
GetMagickPackageName(void)344 MagickExport const char *GetMagickPackageName(void)
345 {
346   return(MagickPackageName);
347 }
348 
349 /*
350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351 %                                                                             %
352 %                                                                             %
353 %                                                                             %
354 %   G e t M a g i c k Q u a n t u m D e p t h                                 %
355 %                                                                             %
356 %                                                                             %
357 %                                                                             %
358 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
359 %
360 %  GetMagickQuantumDepth() returns the ImageMagick quantum depth.
361 %
362 %  The format of the GetMagickQuantumDepth method is:
363 %
364 %      const char *GetMagickQuantumDepth(size_t *depth)
365 %
366 %  A description of each parameter follows:
367 %
368 %    o depth: the quantum depth is returned as a number.
369 %
370 */
GetMagickQuantumDepth(size_t * depth)371 MagickExport const char *GetMagickQuantumDepth(size_t *depth)
372 {
373   if (depth != (size_t *) NULL)
374     *depth=(size_t) MAGICKCORE_QUANTUM_DEPTH;
375   return(MagickQuantumDepth);
376 }
377 
378 /*
379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380 %                                                                             %
381 %                                                                             %
382 %                                                                             %
383 %   G e t M a g i c k Q u a n t u m R a n g e                                 %
384 %                                                                             %
385 %                                                                             %
386 %                                                                             %
387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388 %
389 %  GetMagickQuantumRange() returns the ImageMagick quantum range.
390 %
391 %  The format of the GetMagickQuantumRange method is:
392 %
393 %      const char *GetMagickQuantumRange(size_t *range)
394 %
395 %  A description of each parameter follows:
396 %
397 %    o range: the quantum range is returned as a number.
398 %
399 */
GetMagickQuantumRange(size_t * range)400 MagickExport const char *GetMagickQuantumRange(size_t *range)
401 {
402   if (range != (size_t *) NULL)
403     *range=(size_t) QuantumRange;
404   return(MagickQuantumRange);
405 }
406 
407 /*
408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 %                                                                             %
410 %                                                                             %
411 %                                                                             %
412 %   G e t M a g i c k R e l e a s e D a t e                                   %
413 %                                                                             %
414 %                                                                             %
415 %                                                                             %
416 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
417 %
418 %  GetMagickReleaseDate() returns the ImageMagick release date.
419 %
420 %  The format of the GetMagickReleaseDate method is:
421 %
422 %      const char *GetMagickReleaseDate(void)
423 %
424 %  No parameters are required.
425 %
426 */
GetMagickReleaseDate(void)427 MagickExport const char *GetMagickReleaseDate(void)
428 {
429   return(MagickReleaseDate);
430 }
431 
432 /*
433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
434 %                                                                             %
435 %                                                                             %
436 %                                                                             %
437 %   G e t M a g i c k S i g n a t u r e                                       %
438 %                                                                             %
439 %                                                                             %
440 %                                                                             %
441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
442 %
443 %  GetMagickSignature() returns a signature that uniquely encodes the
444 %  MagickCore libary version, quantum depth, HDRI status, OS word size, and
445 %  endianness.
446 %
447 %  The format of the GetMagickSignature method is:
448 %
449 %      unsigned int GetMagickSignature(const StringInfo *nonce)
450 %
451 %  A description of each parameter follows:
452 %
453 %    o nonce: arbitrary data.
454 %
455 */
456 
CRC32(const unsigned char * message,const size_t length)457 static unsigned int CRC32(const unsigned char *message,const size_t length)
458 {
459   register ssize_t
460     i;
461 
462   static MagickBooleanType
463     crc_initial = MagickFalse;
464 
465   static unsigned int
466     crc_xor[256];
467 
468   unsigned int
469     crc;
470 
471   /*
472     Generate a 32-bit cyclic redundancy check for the message.
473   */
474   if (crc_initial == MagickFalse)
475     {
476       register unsigned int
477         i;
478 
479       unsigned int
480         alpha;
481 
482       for (i=0; i < 256; i++)
483       {
484         register ssize_t
485           j;
486 
487         alpha=i;
488         for (j=0; j < 8; j++)
489           alpha=(alpha & 0x01) ? (0xEDB88320 ^ (alpha >> 1)) : (alpha >> 1);
490         crc_xor[i]=alpha;
491       }
492       crc_initial=MagickTrue;
493     }
494   crc=0xFFFFFFFF;
495   for (i=0; i < (ssize_t) length; i++)
496     crc=crc_xor[(crc ^ message[i]) & 0xff] ^ (crc >> 8);
497   return(crc ^ 0xFFFFFFFF);
498 }
499 
GetMagickSignature(const StringInfo * nonce)500 MagickExport unsigned int GetMagickSignature(const StringInfo *nonce)
501 {
502   register unsigned char
503     *p;
504 
505   StringInfo
506     *version;
507 
508   unsigned int
509     signature;
510 
511   version=AcquireStringInfo(MagickPathExtent);
512   p=GetStringInfoDatum(version);
513   signature=MAGICKCORE_QUANTUM_DEPTH;
514   (void) memcpy(p,&signature,sizeof(signature));
515   p+=sizeof(signature);
516   signature=MAGICKCORE_HDRI_ENABLE;
517   (void) memcpy(p,&signature,sizeof(signature));
518   p+=sizeof(signature);
519   signature=MagickLibInterface;
520   (void) memcpy(p,&signature,sizeof(signature));
521   p+=sizeof(signature);
522   signature=1;  /* endianess */
523   (void) memcpy(p,&signature,sizeof(signature));
524   p+=sizeof(signature);
525   SetStringInfoLength(version,p-GetStringInfoDatum(version));
526   if (nonce != (const StringInfo *) NULL)
527     ConcatenateStringInfo(version,nonce);
528   signature=CRC32(GetStringInfoDatum(version),GetStringInfoLength(version));
529   version=DestroyStringInfo(version);
530   return(signature);
531 }
532 
533 /*
534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
535 %                                                                             %
536 %                                                                             %
537 %                                                                             %
538 %   G e t M a g i c k V e r s i o n                                           %
539 %                                                                             %
540 %                                                                             %
541 %                                                                             %
542 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
543 %
544 %  GetMagickVersion() returns the ImageMagick API version as a string and
545 %  as a number.
546 %
547 %  The format of the GetMagickVersion method is:
548 %
549 %      const char *GetMagickVersion(size_t *version)
550 %
551 %  A description of each parameter follows:
552 %
553 %    o version: the ImageMagick version is returned as a number.
554 %
555 */
GetMagickVersion(size_t * version)556 MagickExport const char *GetMagickVersion(size_t *version)
557 {
558   if (version != (size_t *) NULL)
559     *version=MagickLibVersion;
560   return(MagickVersion);
561 }
562 
563 /*
564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
565 %                                                                             %
566 %                                                                             %
567 %                                                                             %
568 %   L i s t M a g i c k V e r s i o n                                         %
569 %                                                                             %
570 %                                                                             %
571 %                                                                             %
572 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
573 %
574 %  ListMagickVersion() identifies the ImageMagick version by printing its
575 %  attributes to the file.  Attributes include the copyright, features, and
576 %  delegates.
577 %
578 %  The format of the ListMagickVersion method is:
579 %
580 %      void ListMagickVersion(FILE *file)
581 %
582 %  A description of each parameter follows:
583 %
584 %    o file: the file, typically stdout.
585 %
586 */
ListMagickVersion(FILE * file)587 MagickExport void ListMagickVersion(FILE *file)
588 {
589   (void) FormatLocaleFile(file,"Version: %s\n",
590     GetMagickVersion((size_t *) NULL));
591   (void) FormatLocaleFile(file,"Copyright: %s\n",GetMagickCopyright());
592   (void) FormatLocaleFile(file,"License: %s\n",GetMagickLicense());
593 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && defined(_MSC_FULL_VER)
594   (void) FormatLocaleFile(file,"Visual C++: %d\n",_MSC_FULL_VER);
595 #endif
596   (void) FormatLocaleFile(file,"Features: %s\n",GetMagickFeatures());
597   (void) FormatLocaleFile(file,"Delegates (built-in): %s\n",
598     GetMagickDelegates());
599 }
600