/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk

« back to all changes in this revision

Viewing changes to dict_hw/src/win/dll.c

  • Committer: Suren A. Chilingaryan
  • Date: 2010-08-17 01:41:15 UTC
  • Revision ID: csa@dside.dyndns.org-20100817014115-xbh0h6086nz5sj2o
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <windows.h>
 
3
#include "../dict_hw.h"
 
4
 
 
5
#define uint64_t unsigned __int64
 
6
#define uint32_t unsigned __int32
 
7
 
 
8
__declspec(dllexport) uint64_t DictInit(uint32_t ncp, uint32_t corrsize, float *x, float *y, uint32_t *ret) {
 
9
    int err;
 
10
    DICTContext ctx = dictCreateContext();
 
11
    if (ctx) {
 
12
        err = dictSetup(ctx, ncp, corrsize?corrsize:15, 1, 0);
 
13
        if (!err) err = dictSetTemplatePoints((DICTContext)ctx, x, y);
 
14
        if (!err) err = dictSetCurrentPoints((DICTContext)ctx, x, y);
 
15
 
 
16
        if (err) {
 
17
            dictDestroyContext(ctx);
 
18
            ctx = NULL;
 
19
        }
 
20
 
 
21
        if (ret) *ret = err;
 
22
    } else if (ret) *ret = DICT_ERROR_MALLOC;
 
23
    
 
24
    
 
25
    return (uint64_t)ctx;
 
26
}
 
27
 
 
28
__declspec(dllexport) void DictFree(uint64_t ctx, uint32_t *ret) {
 
29
    if (ctx) {
 
30
        dictDestroyContext((DICTContext)ctx);
 
31
    }
 
32
}
 
33
 
 
34
__declspec(dllexport) void DictGrid(uint64_t ctx, float *x, float *y, uint32_t *ret) {
 
35
    int err;
 
36
    
 
37
    if ((!ctx)||(!x)||(!y)) return;
 
38
    if ((ret)&&(*ret)) return;
 
39
    
 
40
    err = dictSetTemplatePoints((DICTContext)ctx, x, y);
 
41
    if (!err) err = dictSetCurrentPoints((DICTContext)ctx, x, y);
 
42
    
 
43
    if (ret) *ret = err;
 
44
}
 
45
 
 
46
__declspec(dllexport) void DictLoadTemplateFile(uint64_t ctx, const char *name, uint32_t *ret) {
 
47
    int err;
 
48
    
 
49
    if ((!ctx)||(!name)) return;
 
50
    if ((ret)&&(*ret)) return;
 
51
 
 
52
    err = dictLoadTemplateImageFile((DICTContext)ctx, name);
 
53
    if (ret) *ret = err;
 
54
    
 
55
}
 
56
 
 
57
__declspec(dllexport) void DictLoadTemplate(uint64_t ctx, const unsigned char *img, uint32_t width, uint32_t height, uint32_t *ret) {
 
58
    int err;
 
59
 
 
60
    if ((!ctx)||(!img)||(!width)||(!height)) return;
 
61
    if ((ret)&&(*ret)) return;
 
62
 
 
63
    err = dictLoadTemplateImage((DICTContext)ctx, img, width, height);
 
64
    if (ret) *ret = err;
 
65
}
 
66
 
 
67
 
 
68
__declspec(dllexport) void DictProcessFile(uint64_t ctx, const char *name, float *x, float *y, uint32_t *ret) {
 
69
    int err;
 
70
    
 
71
    if ((!ctx)||(!name)||(!x)||(!y)) return;
 
72
    if ((ret)&&(*ret)) return;
 
73
 
 
74
    err = dictLoadImageFile((DICTContext)ctx, name);
 
75
    if (!err) err = dictGetCurrentPoints((DICTContext)ctx, x, y);
 
76
    if (ret) *ret = err;
 
77
}
 
78
 
 
79
 
 
80
__declspec(dllexport) void DictProcess(uint64_t ctx, const char *img, float *x, float *y, uint32_t *ret) {
 
81
    int err;
 
82
    
 
83
    if ((!ctx)||(!img)||(!x)||(!y)) return;
 
84
    if ((ret)&&(*ret)) return;
 
85
 
 
86
    err = dictLoadImage((DICTContext)ctx, img);
 
87
    if (!err) err = dictGetCurrentPoints((DICTContext)ctx, x, y);
 
88
    if (ret) *ret = err;
 
89
}
 
90
 
 
91
BOOL WINAPI DllMain(HINSTANCE dllhandle, DWORD reason, LPVOID reserved)
 
92
{
 
93
    int err;
 
94
    switch (reason) {
 
95
    case DLL_PROCESS_ATTACH:
 
96
        /*          ctx = NULL;
 
97
                    dsDebugSetMethod(DS_DEBUG_METHOD_FILE, OPC_LABVIEW_DATA_DIRECTORY "\\opc.log");
 
98
                    dsDebugSetLevel(DS_DEBUG_ERROR);
 
99
                    dsDebugServer(DS_DEBUG_NOTICE, "opcLabview Loading");
 
100
                    err = opcServerInit();
 
101
                    if (!err) err = dsLockInitContext(&lock);
 
102
                    if (!err) {
 
103
                        status = 1;
 
104
                        break;
 
105
                    }*/
 
106
    case DLL_PROCESS_DETACH:
 
107
        /*          if (status) dsLockFreeContext(&lock);
 
108
                    opcServerDestroy();
 
109
                    dsDebugServer(DS_DEBUG_NOTICE, "opcLabview Unloading");
 
110
                    if (err) return FALSE;*/
 
111
        break;
 
112
 
 
113
    case DLL_THREAD_ATTACH:
 
114
        break;
 
115
 
 
116
    case DLL_THREAD_DETACH:
 
117
        break;
 
118
    }
 
119
 
 
120
    return TRUE;
 
121
}