testthread.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include <windows.h>
  2. #include "lcms2_plugin.h"
  3. static cmsContext ctx;
  4. static cmsHPROFILE prof_cmyk, prof_rgb;
  5. static volatile int rc = 0;
  6. static
  7. void* MyMtxCreate(cmsContext id)
  8. {
  9. return (void*) CreateMutex( NULL, FALSE, NULL);
  10. }
  11. static
  12. void MyMtxDestroy(cmsContext id, void* mtx)
  13. {
  14. CloseHandle((HANDLE) mtx);
  15. }
  16. static
  17. cmsBool MyMtxLock(cmsContext id, void* mtx)
  18. {
  19. WaitForSingleObject((HANDLE) mtx, INFINITE);
  20. return TRUE;
  21. }
  22. static
  23. void MyMtxUnlock(cmsContext id, void* mtx)
  24. {
  25. ReleaseMutex((HANDLE) mtx);
  26. }
  27. static cmsPluginMutex MutexPluginSample = {
  28. { cmsPluginMagicNumber, 2060, cmsPluginMutexSig, NULL},
  29. MyMtxCreate, MyMtxDestroy, MyMtxLock, MyMtxUnlock
  30. };
  31. static DWORD WINAPI one_thread(LPVOID lpParameter)
  32. {
  33. int i, j;
  34. cmsUInt8Number rgb[3*1000];
  35. cmsUInt8Number cmyk[4*1000];
  36. Sleep(rand() % 500 );
  37. cmsHTRANSFORM xform = cmsCreateTransformTHR(ctx, prof_rgb, TYPE_RGB_8, prof_cmyk, TYPE_CMYK_8, 0, 0);
  38. for (i=0; i < 100000; i++) {
  39. for (j=0; j < 1000; j++)
  40. {
  41. rgb[j * 3 ] = 189;
  42. rgb[j * 3 + 1] = 100;
  43. rgb[j * 3 + 2] = 75;
  44. }
  45. cmsDoTransform(xform, rgb, cmyk, 1000);
  46. for (j=0; j < 1000; j++)
  47. {
  48. if (cmyk[j * 4 ] != 37 ||
  49. cmyk[j * 4 + 1 ] != 188 ||
  50. cmyk[j * 4 + 2 ] != 195 ||
  51. cmyk[j * 4 + 3 ] != 7)
  52. {
  53. OutputDebugString(L"ERROR\n");
  54. rc = 1;
  55. }
  56. }
  57. }
  58. cmsDeleteTransform(xform);
  59. return 0;
  60. }
  61. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
  62. {
  63. int i;
  64. cmsContext ctx;
  65. OutputDebugString(L"Test in progress...\n");
  66. ctx = cmsCreateContext(NULL, 0);
  67. prof_cmyk = cmsOpenProfileFromFileTHR(ctx, "USWebCoatedSWOP.icc", "r");
  68. prof_rgb = cmsOpenProfileFromFileTHR(ctx, "AdobeRGB1998.icc","r");
  69. #define NWORKERS 10
  70. HANDLE workers[NWORKERS];
  71. for (int i=0; i<NWORKERS; ++i)
  72. {
  73. DWORD threadid;
  74. workers[i] = CreateThread(NULL,0,one_thread,NULL,0,&threadid);
  75. }
  76. WaitForMultipleObjects(NWORKERS,workers,TRUE,INFINITE);
  77. for ( i=0;i<NWORKERS;++i)
  78. CloseHandle(workers[i]);
  79. cmsCloseProfile(prof_rgb);
  80. cmsCloseProfile(prof_cmyk);
  81. cmsDeleteContext(ctx);
  82. OutputDebugString(L"Test Done\n");
  83. return rc;
  84. }