summaryrefslogtreecommitdiff
path: root/util/colorsync-perf.c
blob: fb1fd6dc9140041767fbe07384dc209ad6e6a98e (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
#include <ApplicationServices/ApplicationServices.h>
#include <dlfcn.h>
#include <stdio.h>

#define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipLast)


int main(int argc, char **argv) {
	int width = 256;
	int height = 256*256;
	char *input_profile_file = "input.icc";
	char *output_profile_file = "output.icc";
	if (argc >= 3) {
		input_profile_file = argv[1];
		output_profile_file = argv[2];
	}
	CGDataProviderRef input_file = CGDataProviderCreateWithFilename(input_profile_file);
	CGDataProviderRef output_file = CGDataProviderCreateWithFilename(output_profile_file);
	float range[] = {0, 1., 0, 1., 0, 1.};
	CGColorSpaceRef output_profile = CGColorSpaceCreateICCBased(3, range, output_file, NULL);
	CGColorSpaceRef input_profile = CGColorSpaceCreateICCBased(3, range, input_file, NULL);
	CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();

	CGContextRef cin = CGBitmapContextCreate(NULL, width, height,
			8, 4*width, input_profile, BITMAP_INFO);
	CGContextRef cout = CGBitmapContextCreate(NULL, width, height,
			8, 4*width, output_profile, BITMAP_INFO);

	CGRect rect = {{0,0},{width, height}};
	CGImageRef copy = CGBitmapContextCreateImage(cin);
#define LENGTH 256*256*256
	static unsigned char src[LENGTH*3];
	static unsigned char qoutput[LENGTH*3];
	static unsigned char loutput[LENGTH*3];
	int i,j,k,l=0;
	for (i=0; i<256; i++) {
		for (j=0; j<256; j++) {
			for (k=0; k<256; k++) {
				src[l++] = i;
				src[l++] = j;
				src[l++] = k;
			}
		}
	}

	CGDataProviderRef dp = CGDataProviderCreateWithData(NULL, src, height * width * 3, NULL);
	CGImageRef ref = CGImageCreate(width, height, 8, 24, width * 3, input_profile, BITMAP_INFO, dp, NULL, 1, kCGRenderingIntentDefault);
	clock_t qcms_start = clock();
	CGContextDrawImage(cout, rect, ref);
	clock_t qcms_time = clock() - qcms_start;
	printf("ColorSync: %ld\n", qcms_time);
}