/[projet1]/public/pc/shared_libraries/freeimage/v3.12.0/Examples/Plugin/PluginCradle.cpp
Defence Force logotype

Contents of /public/pc/shared_libraries/freeimage/v3.12.0/Examples/Plugin/PluginCradle.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 126 - (show annotations)
Mon Jul 13 12:20:10 2009 UTC (10 years, 7 months ago) by dbug
File size: 9455 byte(s)
Added some shared libraries (UnitTest++, and FreeImage) to avoid having every single project brings its own libraries.
Ideally people should add them in a way we can upgrade versions without breaking things:
-> public/pc/shared_libraries/library_name/library_version/actuall_content
1 // ==========================================================
2 // Loader/Saver Plugin Cradle
3 //
4 // Design and implementation by
5 // - Floris van den Berg (flvdberg@wxs.nl)
6 // - Hervé Drolon (drolon@infonie.fr)
7 //
8 // This file is part of FreeImage 3
9 //
10 // COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
11 // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
12 // THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
13 // OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
14 // CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
15 // THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
16 // SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
17 // PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
18 // THIS DISCLAIMER.
19 //
20 // Use at your own risk!
21 // ==========================================================
22
23 #include <windows.h>
24 #include <stdlib.h>
25
26 #include "FreeImage.h"
27 #include "Utilities.h"
28
29 // ==========================================================
30
31 BOOL APIENTRY
32 DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
33 switch (ul_reason_for_call) {
34 case DLL_PROCESS_ATTACH :
35 case DLL_PROCESS_DETACH :
36 case DLL_THREAD_ATTACH :
37 case DLL_THREAD_DETACH :
38 break;
39 }
40
41 return TRUE;
42 }
43
44 // ==========================================================
45 // Plugin Interface
46 // ==========================================================
47
48 static int s_format_id;
49
50 // ==========================================================
51 // Plugin Implementation
52 // ==========================================================
53
54 /**
55 Returns the format string for the plugin. Each plugin,
56 both internal in the DLL and external in a .fip file, must have
57 a unique format string to be addressable.
58 */
59
60 static const char * DLL_CALLCONV
61 Format() {
62 return "CRADLE";
63 }
64
65 /**
66 Returns a description string for the plugin. Though a
67 description is not necessary per-se,
68 it is advised to return an unique string in order to tell the
69 user what type of bitmaps this plugin will read and/or write.
70 */
71
72 static const char * DLL_CALLCONV
73 Description() {
74 return "Here comes the description for your image loader/saver";
75 }
76
77 /**
78 Returns a comma separated list of file extensions indicating
79 what files this plugin can open. no spaces or whatsoever are allowed.
80 The list, being used by FreeImage_GetFIFFromFilename, is usually
81 used as a last resort in finding the type of the bitmap we
82 are dealing with. Best is to check the first few bytes on
83 the low-level bits level first and compare them with a known
84 signature . If this fails, FreeImage_GetFIFFromFilename can be
85 used.
86 */
87
88 static const char * DLL_CALLCONV
89 Extension() {
90 return "ext1,ext2";
91 }
92
93 /**
94 RegExpr is only needed for the Qt wrapper
95 It allows the Qt mechanism for loading bitmaps to identify the bitmap
96 */
97 static const char * DLL_CALLCONV
98 RegExpr() {
99 return NULL;
100 }
101
102 /**
103 Returns a MIME content type string for that format (MIME stands
104 for Multipurpose Internet Mail Extension).
105 */
106 static const char * DLL_CALLCONV
107 MimeType() {
108 return "image/myformat";
109 }
110
111 /**
112 FreeImage's internal way of seeing if a bitmap is of the desired type.
113 When the type of a bitmap is to be retrieved, FreeImage runs Validate
114 for each registered plugin until one returns true. If a plugin doesn't
115 have a validate function, a return value of false is assumed.
116
117 You can always force to use a particular plugin by directly specifying
118 it on the command line, but this can result in a dead DLL if the plugin
119 was not made for the bitmap.
120 */
121 static BOOL DLL_CALLCONV
122 Validate(FreeImageIO &io, fi_handle handle) {
123 return FALSE;
124 }
125
126 /**
127 SupportsExportDepth is the first in a possible range of new plugin functions
128 to ask specific information to that plugin. This function returns TRUE if it
129 can save a bitmap in the required bitdepth. If it can't the bitmap has to be
130 converted by the user or another plugin has to be chosen.
131 */
132 static BOOL DLL_CALLCONV
133 SupportsExportDepth(int depth) {
134 return FALSE;
135 }
136
137 /**
138 Returns TRUE if the plugin belonging to the given FREE_IMAGE_FORMAT can save a
139 bitmap in the desired data type, returns FALSE otherwise. Currently, TIFF is the only plugin
140 able to save all non-standard images. The PNG plugin is able to save unsigned 16-bit
141 images.
142 */
143 static BOOL DLL_CALLCONV
144 SupportsExportType(FREE_IMAGE_TYPE type) {
145 return (type == FIT_BITMAP) ? TRUE : FALSE;
146 }
147
148 /**
149 SupportsICCProfiles informs FreeImage that a plugin supports ICC profiles.
150 This function returns TRUE if the plugin can load and save a profile.
151 ICC profile information is accessed via freeimage->get_icc_profile_proc(dib)
152 */
153 static BOOL DLL_CALLCONV
154 SupportsICCProfiles() {
155 return FALSE;
156 }
157
158
159 // ----------------------------------------------------------
160
161 /**
162 Loads a bitmap into memory. On entry it is assumed that
163 the bitmap to be loaded is of the correct type. If the bitmap
164 is of an incorrect type, the plugin might not gracefully fail but
165 crash or enter an endless loop. It is also assumed that all
166 the bitmap data is available at one time. If the bitmap is not complete,
167 for example because it is being downloaded while loaded, the plugin
168 might also not gracefully fail.
169
170 The Load function has the following parameters:
171
172 The first parameter (FreeImageIO *io) is a structure providing
173 function pointers in order to make use of FreeImage's IO redirection. Using
174 FreeImage's file i/o functions instead of standard ones it is garantueed
175 that all bitmap types, both current and future ones, can be loaded from
176 memory, file cabinets, the internet and more. The second parameter (fi_handle handle)
177 is a companion of FreeImageIO and can be best compared with the standard FILE* type,
178 in a generalized form.
179
180 The third parameter (int page) indicates wether we will be loading a certain page
181 in the bitmap or if we will load the default one. This parameter is only used if
182 the plugin supports multi-paged bitmaps, e.g. cabinet bitmaps that contain a series
183 of images or pages. If the plugin does support multi-paging, the page parameter
184 can contain either a number higher or equal to 0 to load a certain page, or -1 to
185 load the default page. If the plugin does not support multi-paging,
186 the page parameter is always -1.
187
188 The fourth parameter (int flags) manipulates the load function to load a bitmap
189 in a certain way. Every plugin has a different flag parameter with different meanings.
190
191 The last parameter (void *data) can contain a special data block used when
192 the file is read multi-paged. Because not every plugin supports multi-paging
193 not every plugin will use the data parameter and it will be set to NULL.However,
194 when the plugin does support multi-paging the parameter contains a pointer to a
195 block of data allocated by the Open function.
196 */
197
198 static FIBITMAP * DLL_CALLCONV
199 Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
200 return NULL;
201 }
202
203 static BOOL DLL_CALLCONV
204 Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
205 return FALSE;
206 }
207
208 // ==========================================================
209 // Init
210 // ==========================================================
211
212 /**
213 Initialises the plugin. The first parameter (Plugin *plugin)
214 contains a pointer to a pre-allocated Plugin structure
215 wherein pointers to the available plugin functions
216 has to be stored. The second parameter (int format_id) is an identification
217 number that the plugin may use to show plugin specific warning messages
218 or other information to the user. The plugin number
219 is generated by FreeImage and can differ everytime the plugin is
220 initialised.
221
222 If you want to create your own plugin you have to take some
223 rules into account. Plugin functions have to be compiled
224 __stdcall using the multithreaded c runtime libraries. Throwing
225 exceptions in plugin functions is allowed, as long as those exceptions
226 are being caught inside the same plugin. It is forbidden for a plugin
227 function to directly call FreeImage functions or to allocate memory
228 and pass it to the main DLL. Exception to this rule is the special file data
229 block that may be allocated the Open function. Allocating a FIBITMAP inside a
230 plugin can be using the function allocate_proc in the FreeImage structure,
231 which will allocate the memory using the DLL's c runtime library.
232 */
233
234 void DLL_CALLCONV
235 Init(Plugin *plugin, int format_id) {
236 s_format_id = format_id;
237
238 plugin->format_proc = Format;
239 plugin->description_proc = Description;
240 plugin->extension_proc = Extension;
241 plugin->regexpr_proc = RegExpr;
242 plugin->open_proc = NULL;
243 plugin->close_proc = NULL;
244 plugin->pagecount_proc = NULL;
245 plugin->pagecapability_proc = NULL;
246 plugin->load_proc = Load;
247 plugin->save_proc = Save;
248 plugin->validate_proc = Validate;
249 plugin->mime_proc = MimeType;
250 plugin->supports_export_bpp_proc = SupportsExportDepth;
251 plugin->supports_export_type_proc = SupportsExportType;
252 plugin->supports_icc_profiles_proc = SupportsICCProfiles;
253 }

  ViewVC Help
Powered by ViewVC 1.1.26