summaryrefslogtreecommitdiff
path: root/TestAPI/testChannels.cpp
blob: 40c7bc47478bb29fbce31c7d42d69b45748bed68 (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
// ==========================================================
// 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"

// Local test functions
// ----------------------------------------------------------

void test24BitsChannels(unsigned width, unsigned height) {
	BOOL bResult = FALSE;

	// create a test 8-bit image
	FIBITMAP *src = createZonePlateImage(width, height, 128);
	if(src != NULL) {
		// convert to 24-bit
		FIBITMAP *tmp = FreeImage_ConvertTo24Bits(src);
		FreeImage_Unload(src);
		src = tmp;
	}
	assert(src != NULL);

	// save for further examination
	bResult = FreeImage_Save(FIF_PNG, src, "zoneplate.png", PNG_DEFAULT);
	assert(bResult);

	// test get/set channel
	// -------------------------	
	FIBITMAP *channel = FreeImage_GetChannel(src, FICC_GREEN);
	assert(channel != NULL);
	bResult = FreeImage_SetChannel(src, channel, FICC_GREEN);
	assert(bResult);	
	FreeImage_Unload(channel);

	FreeImage_Unload(src);
}

void test32BitsChannels(unsigned width, unsigned height) {
	BOOL bResult = FALSE;

	// create a test 8-bit image
	FIBITMAP *src = createZonePlateImage(width, height, 128);
	if(src != NULL) {
		// convert to 32-bit
		FIBITMAP *tmp = FreeImage_ConvertTo32Bits(src);
		FreeImage_Unload(src);
		src = tmp;
	}
	assert(src != NULL);

	// save for further examination
	bResult = FreeImage_Save(FIF_PNG, src, "zoneplate.png", PNG_DEFAULT);
	assert(bResult);

	// test get/set channel
	// -------------------------	
	FIBITMAP *channel = FreeImage_GetChannel(src, FICC_ALPHA);
	assert(channel != NULL);
	bResult = FreeImage_SetChannel(src, channel, FICC_ALPHA);
	assert(bResult);	
	FreeImage_Unload(channel);

	FreeImage_Unload(src);
}

void testRGBAChannels(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height, BOOL bUseAlpha) {
	BOOL bResult = FALSE;

	// create a test image
	FIBITMAP *src = FreeImage_AllocateT(image_type, width, height);
	assert(src != NULL);

	// test get/set channel
	// -------------------------	
	{
		FIBITMAP *channel = FreeImage_GetChannel(src, FICC_GREEN);
		assert(channel != NULL);
		bResult = FreeImage_SetChannel(src, channel, FICC_GREEN);
		assert(bResult);	
		FreeImage_Unload(channel);
	}
	
	if(bUseAlpha) {
		FIBITMAP *alpha = FreeImage_GetChannel(src, FICC_ALPHA);
		assert(alpha != NULL);
		bResult = FreeImage_SetChannel(src, alpha, FICC_ALPHA);
		assert(bResult);	
		FreeImage_Unload(alpha);
	}

	FreeImage_Unload(src);
}

// Main test functions
// ----------------------------------------------------------

void testImageChannels(unsigned width, unsigned height) {

	BOOL bResult = FALSE;

	printf("testImageChannels ...");

	test24BitsChannels(width, height);
	test32BitsChannels(width, height);

	testRGBAChannels(FIT_RGB16, width, height, FALSE);
	testRGBAChannels(FIT_RGBA16, width, height, TRUE);

	testRGBAChannels(FIT_RGBF, width, height, FALSE);
	testRGBAChannels(FIT_RGBAF, width, height, TRUE);

	printf("\tOK\n");
}