summaryrefslogtreecommitdiff
path: root/testbed/testthread.cpp
blob: b932761202a4dcc9400af8376e7c518a1d9a7ca1 (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

#include <windows.h>
#include "lcms2_plugin.h"

static cmsContext ctx;
static cmsHPROFILE prof_cmyk, prof_rgb;
static volatile int rc = 0;


static
void* MyMtxCreate(cmsContext id)
{
   return (void*) CreateMutex( NULL, FALSE, NULL);   
}

static
void MyMtxDestroy(cmsContext id, void* mtx)
{
    CloseHandle((HANDLE) mtx);
}

static
cmsBool MyMtxLock(cmsContext id, void* mtx)
{
    WaitForSingleObject((HANDLE) mtx, INFINITE);
    return TRUE;
}

static
void MyMtxUnlock(cmsContext id, void* mtx)
{
    ReleaseMutex((HANDLE) mtx);
}


static cmsPluginMutex MutexPluginSample = {
                           
     { cmsPluginMagicNumber, 2060, cmsPluginMutexSig, NULL}, 

     MyMtxCreate,  MyMtxDestroy,  MyMtxLock,  MyMtxUnlock                       
};


static DWORD WINAPI one_thread(LPVOID lpParameter)
{
    int i, j;
    cmsUInt8Number rgb[3*1000];
    cmsUInt8Number cmyk[4*1000];

    Sleep(rand() % 500 );
    cmsHTRANSFORM xform = cmsCreateTransformTHR(ctx, prof_rgb, TYPE_RGB_8, prof_cmyk, TYPE_CMYK_8, 0, 0);

    for (i=0; i < 100000; i++) {

        for (j=0; j < 1000; j++) 
        {
            rgb[j * 3    ] = 189;
            rgb[j * 3 + 1] = 100;
            rgb[j * 3 + 2] = 75;
        }
        cmsDoTransform(xform, rgb, cmyk, 1000);
        for (j=0; j < 1000; j++) 
        {
            if (cmyk[j * 4 ] != 37 ||
                cmyk[j * 4 + 1 ] != 188 ||
                cmyk[j * 4 + 2 ] != 195 ||
                cmyk[j * 4 + 3 ] != 7) 
            {
                OutputDebugString(L"ERROR\n"); 
                rc = 1;
            }

        }

    }
        
    cmsDeleteTransform(xform);

    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
    int i;
    cmsContext ctx;

    OutputDebugString(L"Test in progress...\n"); 

    ctx = cmsCreateContext(NULL, 0);

    prof_cmyk = cmsOpenProfileFromFileTHR(ctx, "USWebCoatedSWOP.icc", "r");
    prof_rgb = cmsOpenProfileFromFileTHR(ctx, "AdobeRGB1998.icc","r");
   

#define NWORKERS 10

    HANDLE workers[NWORKERS];


    for (int i=0; i<NWORKERS; ++i)
    {
        DWORD threadid;

        workers[i] = CreateThread(NULL,0,one_thread,NULL,0,&threadid);
    }

    WaitForMultipleObjects(NWORKERS,workers,TRUE,INFINITE);

    for ( i=0;i<NWORKERS;++i)
        CloseHandle(workers[i]);


    cmsCloseProfile(prof_rgb);
    cmsCloseProfile(prof_cmyk);
    cmsDeleteContext(ctx);

    OutputDebugString(L"Test Done\n"); 

    return rc;
}