colorsync-perf.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <ApplicationServices/ApplicationServices.h>
  2. #include <dlfcn.h>
  3. #include <stdio.h>
  4. #define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipLast)
  5. int main(int argc, char **argv) {
  6. int width = 256;
  7. int height = 256*256;
  8. char *input_profile_file = "input.icc";
  9. char *output_profile_file = "output.icc";
  10. if (argc >= 3) {
  11. input_profile_file = argv[1];
  12. output_profile_file = argv[2];
  13. }
  14. CGDataProviderRef input_file = CGDataProviderCreateWithFilename(input_profile_file);
  15. CGDataProviderRef output_file = CGDataProviderCreateWithFilename(output_profile_file);
  16. float range[] = {0, 1., 0, 1., 0, 1.};
  17. CGColorSpaceRef output_profile = CGColorSpaceCreateICCBased(3, range, output_file, NULL);
  18. CGColorSpaceRef input_profile = CGColorSpaceCreateICCBased(3, range, input_file, NULL);
  19. CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
  20. CGContextRef cin = CGBitmapContextCreate(NULL, width, height,
  21. 8, 4*width, input_profile, BITMAP_INFO);
  22. CGContextRef cout = CGBitmapContextCreate(NULL, width, height,
  23. 8, 4*width, output_profile, BITMAP_INFO);
  24. CGRect rect = {{0,0},{width, height}};
  25. CGImageRef copy = CGBitmapContextCreateImage(cin);
  26. #define LENGTH 256*256*256
  27. static unsigned char src[LENGTH*3];
  28. static unsigned char qoutput[LENGTH*3];
  29. static unsigned char loutput[LENGTH*3];
  30. int i,j,k,l=0;
  31. for (i=0; i<256; i++) {
  32. for (j=0; j<256; j++) {
  33. for (k=0; k<256; k++) {
  34. src[l++] = i;
  35. src[l++] = j;
  36. src[l++] = k;
  37. }
  38. }
  39. }
  40. CGDataProviderRef dp = CGDataProviderCreateWithData(NULL, src, height * width * 3, NULL);
  41. CGImageRef ref = CGImageCreate(width, height, 8, 24, width * 3, input_profile, BITMAP_INFO, dp, NULL, 1, kCGRenderingIntentDefault);
  42. clock_t qcms_start = clock();
  43. CGContextDrawImage(cout, rect, ref);
  44. clock_t qcms_time = clock() - qcms_start;
  45. printf("ColorSync: %ld\n", qcms_time);
  46. }