-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMainTestSuite.cpp
More file actions
175 lines (138 loc) · 4.61 KB
/
MainTestSuite.cpp
File metadata and controls
175 lines (138 loc) · 4.61 KB
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
// ==========================================================
// FreeImage 3 Test Script
//
// Design and implementation by
// - Hervé Drolon (drolon@infonie.fr)
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
#include "TestSuite.h"
#include "FreeImage.hpp"
// ----------------------------------------------------------
/**
FreeImage error handler
@param fif Format / Plugin responsible for the error
@param message Error message
*/
void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) {
printf("\n*** ");
if(fif != FIF_UNKNOWN) {
printf("%s Format\n", FreeImage_GetFormatFromFIF(fif));
}
printf("%s", message);
printf(" ***\n");
}
// ----------------------------------------------------------
int main(int argc, char *argv[]) {
unsigned width = 512;
unsigned height = 512;
#if defined(_DEBUG) && defined(WIN32)
// check for memory leaks at program exit (after the 'return 0')
// through a call to _CrtDumpMemoryLeaks
// note that in debug mode, objects allocated with the new operator
// may be destroyed *after* the end of the main function.
// OpenEXR
// note that OpenEXR produce so called "false memory leaks"
// see http://lists.nongnu.org/archive/html/openexr-devel/2013-11/msg00000.html
// False positive leak in LibJXL
// CMS context in static thread_local variable is never deleted
// https://github.com/libjxl/libjxl/issues/4166
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
#endif
#if defined(FREEIMAGE_LIB) || !defined(WIN32)
FreeImage_Initialise();
#endif
// initialize our own FreeImage error handler
FreeImage_SetOutputMessage(FreeImageErrorHandler);
// test plugins capabilities
showPlugins();
uint32_t depsCount = FreeImage_GetDependenciesCount();
for (uint32_t i = 0; i < depsCount; ++i) {
auto dep = FreeImage_GetDependencyInfo(i);
assert(dep != nullptr);
if (dep->fullVersion) {
printf("%u %s\n", i, dep->fullVersion);
}
while (dep->next) {
if (dep->fullVersion) {
printf(" - %s\n", dep->next->fullVersion);
}
dep = dep->next;
}
}
// test internal image types
testImageType(width, height);
auto bmp = FreeImage_AllocateT(FIT_COMPLEX, 128, 128, 128);
FreeImage_Save(FIF_JPEG, bmp, "failed_to_save.jpg");
FreeImage_Unload(bmp);
#if FREEIMAGE_WITH_LIBJPEG
// test the clone function
testAllocateCloneUnload("exif.jpg");
// test JPEG lossless transform & cropping
testJPEG();
// test Exif raw metadata loading & saving
testExifRaw();
// test thumbnail functions
testThumbnail("exif.jpg", 0);
// test wrapped user buffer
testWrappedBuffer("exif.jpg", 0);
// test views
testCreateView("exif.jpg", 0);
#endif
#if FREEIMAGE_WITH_LIBTIFF
// test loading / saving / converting image types using the TIFF plugin
testImageTypeTIFF(width, height);
// test multipage streaming
testStreamMultiPage("sample.tif");
// test multipage streaming with memory IO
testMultiPageMemory("sample.tif");
#endif
#if FREEIMAGE_WITH_LIBPNG
// test memory IO
testMemIO("sample.png");
// test multipage functions
testMultiPage("sample.png");
// test get/set channel
testImageChannels(width, height);
#endif
#if FREEIMAGE_WITH_LIBJXR
// test memory IO
testMemIO("exif.jxr");
#endif
#if FREEIMAGE_WITH_LIBHEIF
testHeif(FIF_HEIF, "exif.heic", "heif_out.heic");
testHeif(FIF_AVIF, "exif.avif", "avif_out.avif");
#endif
#if FREEIMAGE_WITH_LIBJPEGXL
testJpegXl(FIF_JPEGXL, "exif.jxl", "exif_out.jxl");
testJpegXl(FIF_JPEGXL, "exif_599.jxl", "exif_599_out.jxl");
testJpegXl(FIF_JPEGXL, "exif_rgba.jxl", "exif_rgba_out.jxl");
#endif
#if FREEIMAGE_WITH_LIBPNG && FREEIMAGE_WITH_LIBJPEG
// test loading header only
testHeaderOnly();
#endif
// other tests
testConvertToFloat();
testConvertToColor();
testFindMinMax();
testTmoClamp();
testTmoLinear();
testHistogram();
#if defined(FREEIMAGE_LIB) || !defined(WIN32)
FreeImage_DeInitialise();
#endif
return 0;
}