/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/dict_image.cpp

  • Committer: Suren A. Chilingaryan
  • Date: 2009-12-15 13:54:56 UTC
  • Revision ID: csa@dside.dyndns.org-20091215135456-0q8p63jwg4dzbf6p
Collection of timing information and fix for a crash in non-matlab mode

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <stdio.h>
2
2
#include <stdlib.h>
3
3
 
 
4
#ifdef DICT_HW_MEASURE_TIMINGS
 
5
# include <sys/time.h>
 
6
#endif /* DICT_HW_MEASURE_TIMINGS */
 
7
 
4
8
#include "normxcorr_hw.h"
5
9
#include "normxcorr_hw_msg.h"
6
10
 
30
34
#ifdef DICT_TIFF_SUPPORT
31
35
    unsigned char *image = (unsigned char*)img;
32
36
#endif /* DICT_TIFF_SUPPORT */
33
 
    
 
37
 
34
38
    switch (ps->image_type) {
35
39
#ifdef DICT_TIFF_SUPPORT
36
40
        case DICT_IMAGE_TIFF:
39
43
                    int col = i % height;
40
44
                    int lin = i / height;
41
45
                    int pos = 4*(col * width + lin);
42
 
                    res[i] = roundf(((double)(image[pos] + image[pos+1] + image[pos+2]))/3);
 
46
                    res[i] = rintf(((double)(image[pos] + image[pos+1] + image[pos+2]))/3);
43
47
                }
44
48
            } else {
45
49
                for (int i = 0; i < size; ++i) {
46
50
                    int pos = 4 * i;
47
 
                    res[i] = roundf(((double)(image[pos] + image[pos+1] + image[pos+2]))/3);
 
51
                    res[i] = rintf(((double)(image[pos] + image[pos+1] + image[pos+2]))/3);
48
52
                }
49
53
            }
50
54
        break;
55
59
int dictImageLoadTemplateImage(DICTContext ps, const char *name) {
56
60
#ifdef DICT_TIFF_SUPPORT
57
61
    uint32_t w, h;
 
62
 
 
63
#ifdef DICT_HW_MEASURE_TIMINGS
 
64
    int time;
 
65
    struct timeval tv1, tv2, tv3;
 
66
    gettimeofday(&tv1, NULL);
 
67
#endif /* DICT_HW_MEASURE_TIMINGS */
58
68
    
59
69
    TIFF* tif = TIFFOpen(name, "r");
60
70
    if (!tif) return DICT_ERROR_IMAGE;
83
93
    }
84
94
 
85
95
    if (TIFFReadRGBAImage(tif, w, h, (uint32_t*)ps->image_buf, 0)) {
 
96
#ifdef DICT_HW_MEASURE_TIMINGS
 
97
        gettimeofday(&tv3, NULL);
 
98
#endif /* DICT_HW_MEASURE_TIMINGS */
86
99
        dictReduceImage(ps, ps->image_buf, w, h);
 
100
#ifdef DICT_HW_MEASURE_TIMINGS
 
101
        gettimeofday(&tv2, NULL);
 
102
        time = (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
 
103
        ps->time[13] += time;
 
104
#endif /* DICT_HW_MEASURE_TIMINGS */
 
105
 
87
106
    }
88
107
    
89
108
    TIFFClose(tif);
 
109
 
 
110
#ifdef DICT_HW_MEASURE_TIMINGS
 
111
    gettimeofday(&tv2, NULL);
 
112
    ps->time[12] += (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec) - time;
 
113
#endif /* DICT_HW_MEASURE_TIMINGS */
 
114
 
90
115
    return 0;
91
116
#else
92
117
    return DICT_ERROR_IMAGE;
95
120
 
96
121
int dictImageLoadImage(DICTContext ps, const char *name) {
97
122
#ifdef DICT_TIFF_SUPPORT
 
123
#ifdef DICT_HW_MEASURE_TIMINGS
 
124
    int time;
 
125
    struct timeval tv1, tv2, tv3;
 
126
    gettimeofday(&tv1, NULL);
 
127
#endif /* DICT_HW_MEASURE_TIMINGS */
 
128
 
98
129
    TIFF* tif = TIFFOpen(name, "r");
99
130
    if (!tif) return DICT_ERROR_IMAGE;
100
131
 
101
132
    if (TIFFReadRGBAImage(tif, ps->width, ps->height, (uint32_t*)ps->image_buf, 0)) {
 
133
#ifdef DICT_HW_MEASURE_TIMINGS
 
134
        gettimeofday(&tv3, NULL);
 
135
#endif /* DICT_HW_MEASURE_TIMINGS */
102
136
        dictReduceImage(ps, ps->image_buf, ps->width, ps->height);
 
137
#ifdef DICT_HW_MEASURE_TIMINGS
 
138
        gettimeofday(&tv2, NULL);
 
139
        time = (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
 
140
        ps->time[15] += time;
 
141
#endif /* DICT_HW_MEASURE_TIMINGS */
103
142
    }
 
143
 
104
144
    TIFFClose(tif);
 
145
 
 
146
#ifdef DICT_HW_MEASURE_TIMINGS
 
147
    gettimeofday(&tv2, NULL);
 
148
    ps->time[14] += (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec) - time;
 
149
#endif /* DICT_HW_MEASURE_TIMINGS */
105
150
    return 0;
106
151
#else
107
152
    return DICT_ERROR_IMAGE;