Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dynlibtiff.c « intern « imbuf « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 31da262ffdb730e4e52e31d45293cb774bc5e834 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/**
 * Dynamically loaded libtiff support.
 *
 * This file is automatically generated by the gen_dynlibtiff.py script.
 * 
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor(s): Jonathan Merritt.
 *
 * ***** END GPL LICENSE BLOCK *****
 */
 
/**
 * To use the dynamic libtiff support, you must initialize the library using:
 *	libtiff_init()
 * This attempts to load libtiff dynamically at runtime.  G.have_libtiff will
 * be set to indicate whether or not libtiff is available.  If libtiff is
 * not available, Blender can proceed with no ill effects, provided that
 * it does not attempt to use any of the libtiff_ functions.  When you're
 * finished, close the library with:
 *	libtiff_exit()
 * These functions are both declared in IMB_imbuf.h
 *
 * The functions provided by dyn_libtiff.h are the same as those in the
 * normal static / shared libtiff, except that they are prefixed by the 
 * string "libtiff_" to indicate that they belong to a dynamically-loaded 
 * version.
 */
#include "dynlibtiff.h"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

#include "BLI_blenlib.h"

#include "imbuf.h"
#include "imbuf_patch.h"
#include "IMB_imbuf.h"

#include "BKE_global.h"
#include "PIL_dynlib.h"

/*********************
 * LOCAL DEFINITIONS *
 *********************/
PILdynlib *libtiff = NULL;
void  libtiff_loadlibtiff(void);
void* libtiff_findsymbol(char*);
int   libtiff_load_symbols(void);


/**************************
 * LIBRARY INITIALIZATION *
 **************************/

void libtiff_loadlibtiff(void)
{
	char *filename;
	libtiff = NULL;

	filename = getenv("BF_TIFF_LIB");
	if (filename) libtiff = PIL_dynlib_open(filename);
	if (libtiff != NULL)  return;

	/* Try to find libtiff in a couple of standard places */
#ifdef __APPLE__
	/* OSX has version specific library */
	//standard install location
	libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.dylib");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.3.dylib");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.4.dylib");
	if (libtiff != NULL)  return;
	//inside the blender app package contents/resources
	libtiff = PIL_dynlib_open("@executable_path/../resources/libtiff.dylib");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("@executable_path/../resources/libtiff.3.dylib");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("@executable_path/../resources/libtiff.4.dylib");
	if (libtiff != NULL)  return;
	//inside the blender app package contents/frameworks
	libtiff = PIL_dynlib_open("@executable_path/../frameworks/libtiff.dylib");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("@executable_path/../frameworks/libtiff.3.dylib");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("@executable_path/../frameworks/libtiff.4.dylib");
	if (libtiff != NULL)  return;
	//along side the blender app package
	libtiff = PIL_dynlib_open("@executable_path/../../../libtiff.dylib");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("@executable_path/../../../libtiff.3.dylib");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("@executable_path/../../../libtiff.4.dylib");
	if (libtiff != NULL)  return;
	//inside the blender app package contents/MacOS
	libtiff = PIL_dynlib_open("@executable_path/libtiff.dylib");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("@executable_path/libtiff.3.dylib");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("@executable_path/libtiff.4.dylib");
	if (libtiff != NULL)  return;
#else
	libtiff = PIL_dynlib_open("libtiff.so");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("libtiff.so.3");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("libtiff.so.4");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("libtiff.dll");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("/usr/lib/libtiff.so");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("/usr/lib/libtiff.so.3");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("/usr/lib/libtiff.so.4");
	if (libtiff != NULL)  return;
#ifdef __x86_64__
	libtiff = PIL_dynlib_open("/usr/lib64/libtiff.so");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("/usr/lib64/libtiff.so.3");
	if (libtiff != NULL)  return;
	libtiff = PIL_dynlib_open("/usr/lib64/libtiff.so.4");
	if (libtiff != NULL)  return;
#endif
	libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.so");
	if (libtiff != NULL)  return;
	/* For solaris */
	libtiff = PIL_dynlib_open("/usr/openwin/lib/libtiff.so");
#endif

}

void *libtiff_findsymbol(char *name)
{
	void *symbol = NULL;
	assert(libtiff != NULL);
	symbol = PIL_dynlib_find_symbol(libtiff, name);
	if (symbol == NULL) {
		char *err = PIL_dynlib_get_error_as_string(libtiff);

		if (err) printf("libtiff_findsymbol: error %s\n",err);
		else printf("libtiff_findsymbol: error Unknown.\n");

		libtiff = NULL;
		G.have_libtiff = (0);
		return NULL;
	}
	return symbol;
}

void libtiff_init(void)
{
	if (libtiff != NULL) {
		printf("libtiff_init: Attempted to load libtiff twice!\n");
		return;
	}
	libtiff_loadlibtiff();
	G.have_libtiff = ((libtiff != NULL) && (libtiff_load_symbols()));
}

void libtiff_exit(void)
{
	if (libtiff != NULL) {
		PIL_dynlib_close(libtiff);
		libtiff = NULL;
	}
}


int libtiff_load_symbols(void)
{
	/* Attempt to load TIFFClientOpen */
	libtiff_TIFFClientOpen = libtiff_findsymbol("TIFFClientOpen");
	if (libtiff_TIFFClientOpen == NULL) {
		return (0);
	}
	/* Attempt to load TIFFClose */
	libtiff_TIFFClose = libtiff_findsymbol("TIFFClose");
	if (libtiff_TIFFClose == NULL) {
		return (0);
	}
	/* Attempt to load TIFFGetField */
	libtiff_TIFFGetField = libtiff_findsymbol("TIFFGetField");
	if (libtiff_TIFFGetField == NULL) {
		return (0);
	}
	/* Attempt to load TIFFOpen */
	libtiff_TIFFOpen = libtiff_findsymbol("TIFFOpen");
	if (libtiff_TIFFOpen == NULL) {
		return (0);
	}
	/* Attempt to load TIFFReadRGBAImage */
	libtiff_TIFFReadRGBAImage = libtiff_findsymbol("TIFFReadRGBAImage");
	if (libtiff_TIFFReadRGBAImage == NULL) {
		return (0);
	}
	/* Attempt to load TIFFSetField */
	libtiff_TIFFSetField = libtiff_findsymbol("TIFFSetField");
	if (libtiff_TIFFSetField == NULL) {
		return (0);
	}
	/* Attempt to load TIFFWriteEncodedStrip */
	libtiff_TIFFWriteEncodedStrip = libtiff_findsymbol("TIFFWriteEncodedStrip");
	if (libtiff_TIFFWriteEncodedStrip == NULL) {
		return (0);
	}
	/* Attempt to load _TIFFfree */
	libtiff__TIFFfree = libtiff_findsymbol("_TIFFfree");
	if (libtiff__TIFFfree == NULL) {
		return (0);
	}
	/* Attempt to load _TIFFmalloc */
	libtiff__TIFFmalloc = libtiff_findsymbol("_TIFFmalloc");
	if (libtiff__TIFFmalloc == NULL) {
		return (0);
	}
	return (1);
}

	
/*******************
 * SYMBOL POINTERS *
 *******************/

TIFF* (*libtiff_TIFFClientOpen)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc) = NULL;
void (*libtiff_TIFFClose)(TIFF*) = NULL;
int (*libtiff_TIFFGetField)(TIFF*, ttag_t, ...) = NULL;
TIFF* (*libtiff_TIFFOpen)(const char*, const char*) = NULL;
int (*libtiff_TIFFReadRGBAImage)(TIFF*, uint32, uint32, uint32*, int) = NULL;
int (*libtiff_TIFFSetField)(TIFF*, ttag_t, ...) = NULL;
tsize_t (*libtiff_TIFFWriteEncodedStrip)(TIFF*, tstrip_t, tdata_t, tsize_t) = NULL;
void (*libtiff__TIFFfree)(tdata_t) = NULL;
tdata_t (*libtiff__TIFFmalloc)(tsize_t) = NULL;