summaryrefslogtreecommitdiff
path: root/coverage.c
blob: 09e0f7fbd89535b18847bddaa024988d96d97c52 (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
#include <stdlib.h>
#include <assert.h>
#include "qcms.h"
const unsigned char gray_icc[] =
{0x00, 0x00, 0x01, 0x70, 0x4E, 0x4B, 0x4F, 0x4E, 0x02, 0x20, 0x00, 0x00,
0x6D, 0x6E, 0x74, 0x72, 0x47, 0x52, 0x41, 0x59, 0x58, 0x59, 0x5A, 0x20,
0x07, 0xCE, 0x00, 0x0B, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x61, 0x63, 0x73, 0x70, 0x41, 0x50, 0x50, 0x4C, 0x00, 0x00, 0x00, 0x00,
0x6E, 0x6F, 0x6E, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF6, 0xD6,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xD3, 0x2D, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
0x64, 0x65, 0x73, 0x63, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x4B,
0x77, 0x74, 0x70, 0x74, 0x00, 0x00, 0x01, 0x0C, 0x00, 0x00, 0x00, 0x14,
0x6B, 0x54, 0x52, 0x43, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x00, 0x0E,
0x63, 0x70, 0x72, 0x74, 0x00, 0x00, 0x01, 0x30, 0x00, 0x00, 0x00, 0x2C,
0x62, 0x6B, 0x70, 0x74, 0x00, 0x00, 0x01, 0x5C, 0x00, 0x00, 0x00, 0x14,
0x64, 0x65, 0x73, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A,
0x4E, 0x69, 0x6B, 0x6F, 0x6E, 0x47, 0x72, 0x61, 0x79, 0x47, 0x31, 0x2E,
0x38, 0x20, 0x76, 0x34, 0x2E, 0x30, 0x2E, 0x30, 0x2E, 0x33, 0x30, 0x30,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1A, 0x4E, 0x69, 0x6B, 0x6F, 0x6E, 0x47, 0x72, 0x61, 0x79, 0x47, 0x31,
0x2E, 0x38, 0x20, 0x76, 0x34, 0x2E, 0x30, 0x2E, 0x30, 0x2E, 0x33, 0x30,
0x30, 0x30, 0x00, 0x00, 0x58, 0x59, 0x5A, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xF3, 0x51, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x16, 0xCC,
0x63, 0x75, 0x72, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x01, 0xCD, 0x00, 0x00, 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0x00,
0x4E, 0x69, 0x6B, 0x6F, 0x6E, 0x20, 0x49, 0x6E, 0x63, 0x2E, 0x20, 0x26,
0x20, 0x4E, 0x69, 0x6B, 0x6F, 0x6E, 0x20, 0x43, 0x6F, 0x72, 0x70, 0x6F,
0x72, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x32, 0x30, 0x30, 0x31, 0x00,
0x58, 0x59, 0x5A, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

void test_gray(qcms_profile *output_profile)
{
	unsigned char srct[3] = { 221, 79, 129};
	unsigned char outt[3];
	qcms_transform *transform;
	qcms_profile *gray_profile = qcms_profile_from_memory(gray_icc, sizeof(gray_icc));
	assert(gray_profile);
	transform = qcms_transform_create(gray_profile, QCMS_DATA_GRAY_8, output_profile, QCMS_DATA_RGB_8, QCMS_INTENT_PERCEPTUAL);
	qcms_transform_data(transform, srct, outt, 1);
	assert(
			outt[0] == 0xe4 &&
			outt[1] == 0xe4 &&
			outt[2] == 0xe4);
	qcms_transform_release(transform);

	transform = qcms_transform_create(gray_profile, QCMS_DATA_GRAYA_8, output_profile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL);
	qcms_transform_data(transform, srct, outt, 1);
	assert(
			outt[0] == 0xe4 &&
			outt[1] == 0xe4 &&
			outt[2] == 0xe4 &&
			outt[3] == 79);
	qcms_transform_release(transform);
	qcms_profile_release(gray_profile);
}

const extern unsigned char gray_icc[];
int main()
{
	unsigned char srct[4] = { 221, 79, 129, 92};
	unsigned char outt[4];
	qcms_transform *transform;
	qcms_profile *input_profile, *output_profile, *rgb;
	qcms_CIE_xyY white_point = { 0, 0.1, 1.};
	qcms_CIE_xyYTRIPLE primaries = { {1, 0.01, 0}, {0, 0, 0.01}, {20, .4, 1.}};

	input_profile = qcms_profile_sRGB();
	output_profile = qcms_profile_sRGB();

	test_gray(output_profile);

	rgb = qcms_profile_create_rgb_with_gamma(white_point, primaries, 1.8);
	// it is not clear how to create a bogus profile with the above interface
	//assert(qcms_profile_is_bogus(rgb));

	assert(!qcms_profile_is_bogus(input_profile));
	assert(!qcms_profile_is_bogus(output_profile));

	transform = qcms_transform_create(input_profile, QCMS_DATA_RGBA_8, output_profile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL);

	qcms_transform_data(transform, srct, outt, 1);
	assert(outt[0] == 0xdd && outt[1] == 0x4f && outt[2] == 0x81 && outt[3] == 92);

	qcms_transform_release(transform);

	transform = qcms_transform_create(input_profile, QCMS_DATA_RGB_8, output_profile, QCMS_DATA_RGB_8, QCMS_INTENT_PERCEPTUAL);

	qcms_transform_data(transform, srct, outt, 1);
	assert(outt[0] == 0xdd && outt[1] == 0x4f && outt[2] == 0x81);

	qcms_transform_release(transform);

	qcms_profile_precache_output_transform(output_profile);

	transform = qcms_transform_create(input_profile, QCMS_DATA_RGBA_8, output_profile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL);

	qcms_transform_data(transform, srct, outt, 1);
	assert(outt[0] == 0xdd && outt[1] == 0x4f && outt[2] == 0x81 && outt[3] == 92);

	qcms_transform_release(transform);

	transform = qcms_transform_create(input_profile, QCMS_DATA_RGB_8, output_profile, QCMS_DATA_RGB_8, QCMS_INTENT_PERCEPTUAL);

	qcms_transform_data(transform, srct, outt, 1);
	assert(outt[0] == 0xdd && outt[1] == 0x4f && outt[2] == 0x81);

	qcms_transform_release(transform);

	test_gray(output_profile);

	qcms_profile_release(input_profile);
	qcms_profile_release(output_profile);

	return 0;
}