-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestConversionFloat.cpp
102 lines (83 loc) · 3.71 KB
/
testConversionFloat.cpp
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
// ==========================================================
// FreeImage 3 Test Script
//
// Design and implementation by
// - Hervé Drolon ([email protected])
//
// 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 <memory>
#include <limits>
/**
Test FreeImage_ConvertToFloat
*/
void testConvertToFloat()
{
{
std::unique_ptr<FIBITMAP, decltype(&::FreeImage_Unload)> bmp_uint16(FreeImage_AllocateT(FIT_UINT16, 5, 1, 16), &::FreeImage_Unload);
assert(bmp_uint16 != nullptr);
uint16_t* bmp_uint16_ptr = reinterpret_cast<uint16_t*>(FreeImage_GetBits(bmp_uint16.get()));
assert(bmp_uint16_ptr != nullptr);
bmp_uint16_ptr[0] = 0;
bmp_uint16_ptr[1] = 255;
bmp_uint16_ptr[2] = 1000;
bmp_uint16_ptr[3] = 10000;
bmp_uint16_ptr[4] = 65535;
std::unique_ptr<FIBITMAP, decltype(&::FreeImage_Unload)> res_scaled(FreeImage_ConvertToFloat(bmp_uint16.get(), TRUE), &::FreeImage_Unload);
assert(res_scaled != nullptr);
float* res_scaled_ptr = reinterpret_cast<float*>(FreeImage_GetBits(res_scaled.get()));
assert(res_scaled_ptr != nullptr);
assert(res_scaled_ptr[0] == 0.0f);
assert(res_scaled_ptr[1] == 255.0f / 65535.0f);
assert(res_scaled_ptr[2] == 1000.0f / 65535.0f);
assert(res_scaled_ptr[3] == 10000.0f / 65535.0f);
assert(res_scaled_ptr[4] == 1.0f);
std::unique_ptr<FIBITMAP, decltype(&::FreeImage_Unload)> res(FreeImage_ConvertToFloat(bmp_uint16.get(), FALSE), &::FreeImage_Unload);
assert(res != nullptr);
float* res_ptr = reinterpret_cast<float*>(FreeImage_GetBits(res.get()));
assert(res_ptr != nullptr);
assert(res_ptr[0] == 0.0f);
assert(res_ptr[1] == 255.0f);
assert(res_ptr[2] == 1000.0f);
assert(res_ptr[3] == 10000.0f);
assert(res_ptr[4] == 65535.0f);
}
{
std::unique_ptr<FIBITMAP, decltype(&::FreeImage_Unload)> bmp_int32(FreeImage_AllocateT(FIT_INT32, 5, 1, 16), &::FreeImage_Unload);
assert(bmp_int32 != nullptr);
int32_t* bmp_uint32_ptr = reinterpret_cast<int32_t*>(FreeImage_GetBits(bmp_int32.get()));
assert(bmp_uint32_ptr != nullptr);
bmp_uint32_ptr[0] = 0;
bmp_uint32_ptr[1] = 255;
bmp_uint32_ptr[2] = 10000;
bmp_uint32_ptr[3] = 65535;
bmp_uint32_ptr[4] = std::numeric_limits<int32_t>::max();
std::unique_ptr<FIBITMAP, decltype(&::FreeImage_Unload)> res_scaled(FreeImage_ConvertToFloat(bmp_int32.get(), TRUE), &::FreeImage_Unload);
assert(res_scaled != nullptr);
float* res_scaled_ptr = reinterpret_cast<float*>(FreeImage_GetBits(res_scaled.get()));
assert(res_scaled_ptr != nullptr);
assert(res_scaled_ptr[0] == 0.0f);
assert(res_scaled_ptr[4] == 1.0f);
std::unique_ptr<FIBITMAP, decltype(&::FreeImage_Unload)> res(FreeImage_ConvertToFloat(bmp_int32.get(), FALSE), &::FreeImage_Unload);
assert(res != nullptr);
float* res_ptr = reinterpret_cast<float*>(FreeImage_GetBits(res.get()));
assert(res_ptr != nullptr);
assert(res_ptr[0] == 0.0f);
assert(res_ptr[1] == 255.0f);
assert(res_ptr[2] == 10000.0f);
assert(res_ptr[3] == 65535.0f);
}
}