Leptonica  1.77.0
Image processing and image analysis suite
libversions.c
Go to the documentation of this file.
1 /*====================================================================*
2  - Copyright (C) 2001 Leptonica. All rights reserved.
3  -
4  - Redistribution and use in source and binary forms, with or without
5  - modification, are permitted provided that the following conditions
6  - are met:
7  - 1. Redistributions of source code must retain the above copyright
8  - notice, this list of conditions and the following disclaimer.
9  - 2. Redistributions in binary form must reproduce the above
10  - copyright notice, this list of conditions and the following
11  - disclaimer in the documentation and/or other materials
12  - provided with the distribution.
13  -
14  - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18  - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *====================================================================*/
26 
36 #ifdef HAVE_CONFIG_H
37 #include "config_auto.h"
38 #endif /* HAVE_CONFIG_H */
39 
40 #include "allheaders.h"
41 
42 #if HAVE_LIBGIF
43 #include "gif_lib.h"
44 #endif
45 
46 #if HAVE_LIBJPEG
47 /* jpeglib.h includes jconfig.h, which makes the error of setting
48  * #define HAVE_STDLIB_H
49  * which conflicts with config_auto.h (where it is set to 1) and results
50  * for some gcc compiler versions in a warning. The conflict is harmless
51  * but we suppress it by undefining the variable. */
52 #undef HAVE_STDLIB_H
53 #include "jpeglib.h"
54 #include "jerror.h"
55 #endif
56 
57 #if HAVE_LIBPNG
58 #include "png.h"
59 #endif
60 
61 #if HAVE_LIBTIFF
62 #include "tiffio.h"
63 #endif
64 
65 #if HAVE_LIBZ
66 #include "zlib.h"
67 #endif
68 
69 #if HAVE_LIBWEBP
70 #include "webp/encode.h"
71 #endif
72 
73 #if HAVE_LIBJP2K
74 #ifdef LIBJP2K_HEADER
75 #include LIBJP2K_HEADER
76 #else
77 #include <openjpeg.h>
78 #endif
79 #endif
80 
81 
82 /*---------------------------------------------------------------------*
83  * Image Library Version number *
84  *---------------------------------------------------------------------*/
100 char *
102 {
103 char buf[128];
104 l_int32 first = TRUE;
105 char *versionNumP;
106 char *nextTokenP;
107 char *versionStrP = NULL;
108 
109 #if HAVE_LIBGIF
110  first = FALSE;
111  stringJoinIP(&versionStrP, "libgif ");
112  #ifdef GIFLIB_MAJOR
113  snprintf(buf, sizeof(buf), "%d.%d.%d", GIFLIB_MAJOR, GIFLIB_MINOR,
114  GIFLIB_RELEASE);
115  #else
116  stringCopy(buf, "4.1.6(?)", sizeof(buf));
117  #endif
118  stringJoinIP(&versionStrP, buf);
119 #endif /* HAVE_LIBGIF */
120 
121 #if HAVE_LIBJPEG
122  {
123  struct jpeg_compress_struct cinfo;
124  struct jpeg_error_mgr err;
125  char buffer[JMSG_LENGTH_MAX];
126  cinfo.err = jpeg_std_error(&err);
127  err.msg_code = JMSG_VERSION;
128  (*err.format_message) ((j_common_ptr ) &cinfo, buffer);
129 
130  if (!first) stringJoinIP(&versionStrP, " : ");
131  first = FALSE;
132  stringJoinIP(&versionStrP, "libjpeg ");
133  versionNumP = strtokSafe(buffer, " ", &nextTokenP);
134  stringJoinIP(&versionStrP, versionNumP);
135  LEPT_FREE(versionNumP);
136 
137  #if defined(LIBJPEG_TURBO_VERSION)
138  /* To stringify the result of expansion of a macro argument,
139  * you must use two levels of macros. See:
140  * https://gcc.gnu.org/onlinedocs/cpp/Stringification.html */
141  #define l_xstr(s) l_str(s)
142  #define l_str(s) #s
143  snprintf(buf, sizeof(buf), " (libjpeg-turbo %s)",
144  l_xstr(LIBJPEG_TURBO_VERSION));
145  stringJoinIP(&versionStrP, buf);
146  #endif /* LIBJPEG_TURBO_VERSION */
147  }
148 #endif /* HAVE_LIBJPEG */
149 
150 #if HAVE_LIBPNG
151  if (!first) stringJoinIP(&versionStrP, " : ");
152  first = FALSE;
153  stringJoinIP(&versionStrP, "libpng ");
154  stringJoinIP(&versionStrP, png_get_libpng_ver(NULL));
155 #endif /* HAVE_LIBPNG */
156 
157 #if HAVE_LIBTIFF
158  if (!first) stringJoinIP(&versionStrP, " : ");
159  first = FALSE;
160  stringJoinIP(&versionStrP, "libtiff ");
161  versionNumP = strtokSafe((char *)TIFFGetVersion(), " \n", &nextTokenP);
162  LEPT_FREE(versionNumP);
163  versionNumP = strtokSafe(NULL, " \n", &nextTokenP);
164  LEPT_FREE(versionNumP);
165  versionNumP = strtokSafe(NULL, " \n", &nextTokenP);
166  stringJoinIP(&versionStrP, versionNumP);
167  LEPT_FREE(versionNumP);
168 #endif /* HAVE_LIBTIFF */
169 
170 #if HAVE_LIBZ
171  if (!first) stringJoinIP(&versionStrP, " : ");
172  first = FALSE;
173  stringJoinIP(&versionStrP, "zlib ");
174  stringJoinIP(&versionStrP, zlibVersion());
175 #endif /* HAVE_LIBZ */
176 
177 #if HAVE_LIBWEBP
178  {
179  l_int32 val;
180  char buf[32];
181  if (!first) stringJoinIP(&versionStrP, " : ");
182  first = FALSE;
183  stringJoinIP(&versionStrP, "libwebp ");
184  val = WebPGetEncoderVersion();
185  snprintf(buf, sizeof(buf), "%d.%d.%d", val >> 16, (val >> 8) & 0xff,
186  val & 0xff);
187  stringJoinIP(&versionStrP, buf);
188  }
189 #endif /* HAVE_LIBWEBP */
190 
191 #if HAVE_LIBJP2K
192  {
193  const char *version;
194  if (!first) stringJoinIP(&versionStrP, " : ");
195  first = FALSE;
196  stringJoinIP(&versionStrP, "libopenjp2 ");
197  version = opj_version();
198  stringJoinIP(&versionStrP, version);
199  }
200 #endif /* HAVE_LIBJP2K */
201 
202  return versionStrP;
203 }
char * getImagelibVersions()
getImagelibVersions()
Definition: libversions.c:101
l_ok stringJoinIP(char **psrc1, const char *src2)
stringJoinIP()
Definition: utils2.c:564
char * strtokSafe(char *cstr, const char *seps, char **psaveptr)
strtokSafe()
Definition: utils2.c:640
l_ok stringCopy(char *dest, const char *src, l_int32 n)
stringCopy()
Definition: utils2.c:255