/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: 2010-04-25 23:10:35 UTC
  • Revision ID: csa@dside.dyndns.org-20100425231035-ggdq59911gurvsu3
Preloading of images

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
#include "dict_image.h"
14
14
 
15
 
int dictImageFreeBuffer(DICTContext ctx, DICTImageType image_type, void *image_buf) {
 
15
static int dictImageFreeBuffer(DICTContext ctx, DICTImageType image_type, void *image_buf) {
16
16
    switch (image_type) {
17
17
#ifdef DICT_TIFF_SUPPORT
18
18
        case DICT_IMAGE_TIFF:
26
26
 
27
27
int dictImageFree(DICTContext ps) {
28
28
    if (ps->image_buf) dictImageFreeBuffer(ps, ps->image_type, ps->image_buf);
 
29
    if (ps->image2) free(ps->image2);
29
30
    if (ps->image) free(ps->image);
30
31
    
31
32
    return 0;
165
166
#endif /*USE_SSE */
166
167
 
167
168
 
168
 
int dictReduceImage(DICTContext ps, void *img, int width, int height) {
 
169
int dictReduceImage(DICTContext ps, unsigned char *res, void *img, int width, int height) {
169
170
    int size = width * height;
170
 
    unsigned char *res = ps->image;
 
171
//    unsigned char *res = ps->image;
171
172
 
172
173
#ifdef DICT_TIFF_SUPPORT
173
174
    unsigned char *image = (unsigned char*)img;
264
265
    if (ps->image) {
265
266
        free(ps->image);
266
267
    }
 
268
    
 
269
    if (ps->image2) {
 
270
        free(ps->image2);
 
271
    }
267
272
 
268
273
    ps->image_type = DICT_IMAGE_TIFF;
269
274
        // we need extra 32 bytes in the end for do20 sse code
270
275
    int alloc_size = 32 + calc_alloc(w * h, 32);
271
276
    ps->image_buf = _TIFFmalloc(alloc_size * sizeof (uint32_t));
272
277
    ps->image = (unsigned char*)malloc(alloc_size * sizeof(unsigned char));
 
278
    ps->image2 = (unsigned char*)malloc(alloc_size * sizeof(unsigned char));
273
279
 
274
280
    dictSetDimensions(ps, w, h);    
275
281
    
276
 
    if ((!ps->image)||(!ps->image_buf)) {
 
282
    if ((!ps->image)||(!ps->image2)||(!ps->image_buf)) {
277
283
        reportError("Problem allocating memory for image %ix%i", w, h);
278
284
        return DICT_ERROR_MALLOC;
279
285
    }
282
288
#ifdef DICT_HW_MEASURE_TIMINGS
283
289
        gettimeofday(&tv3, NULL);
284
290
#endif /* DICT_HW_MEASURE_TIMINGS */
285
 
        dictReduceImage(ps, ps->image_buf, w, h);
 
291
        dictReduceImage(ps, ps->image, ps->image_buf, w, h);
286
292
#ifdef DICT_HW_MEASURE_TIMINGS
287
293
        gettimeofday(&tv2, NULL);
288
294
        time = (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
304
310
#endif /* DICT_TIFF_SUPPORT */
305
311
}
306
312
 
307
 
int dictImageLoadImage(DICTContext ps, const char *name) {
 
313
int dictImageLoadImage(DICTContext ps, const char *name, unsigned char *buf) {
308
314
#ifdef DICT_TIFF_SUPPORT
309
315
#ifdef DICT_HW_MEASURE_TIMINGS
310
316
    int time;
319
325
#ifdef DICT_HW_MEASURE_TIMINGS
320
326
        gettimeofday(&tv3, NULL);
321
327
#endif /* DICT_HW_MEASURE_TIMINGS */
322
 
        dictReduceImage(ps, ps->image_buf, ps->width, ps->height);
 
328
        dictReduceImage(ps, buf?buf:ps->image, ps->image_buf, ps->width, ps->height);
323
329
#ifdef DICT_HW_MEASURE_TIMINGS
324
330
        gettimeofday(&tv2, NULL);
325
331
        time = (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);