4
#include "normxcorr_hw.h"
5
#include "normxcorr_hw_msg.h"
9
#include "dict_image.h"
11
int dictImageFreeBuffer(DICTContext ctx, DICTImageType image_type, void *image_buf) {
13
#ifdef DICT_TIFF_SUPPORT
17
#endif /* DICT_TIFF_SUPPORT */
21
int dictImageFree(DICTContext ps) {
22
if (ps->image_buf) dictImageFreeBuffer(ps, ps->image_type, ps->image_buf);
23
if (ps->image) free(ps->image);
26
int dictReduceImage(DICTContext ps, void *img, int width, int height) {
27
int size = width * height;
28
unsigned char *res = ps->image;
30
#ifdef DICT_TIFF_SUPPORT
31
unsigned char *image = (unsigned char*)img;
32
#endif /* DICT_TIFF_SUPPORT */
34
switch (ps->image_type) {
35
#ifdef DICT_TIFF_SUPPORT
37
if (ps->matlab_mode) {
38
for (int i = 0; i < size; ++i) {
41
int pos = 4*(col * width + lin);
42
res[i] = roundf(((double)(image[pos] + image[pos+1] + image[pos+2]))/3);
45
for (int i = 0; i < size; ++i) {
47
res[i] = roundf(((double)(image[pos] + image[pos+1] + image[pos+2]))/3);
51
#endif /* DICT_TIFF_SUPPORT */
55
int dictImageLoadTemplateImage(DICTContext ps, const char *name) {
56
#ifdef DICT_TIFF_SUPPORT
59
TIFF* tif = TIFFOpen(name, "r");
60
if (!tif) return DICT_ERROR_IMAGE;
62
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
63
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
66
dictImageFreeBuffer(ps, ps->image_type, ps->image_buf);
73
ps->image_type = DICT_IMAGE_TIFF;
74
ps->image_buf = _TIFFmalloc(w * h * sizeof (uint32_t));
75
ps->image = (unsigned char*)malloc(w * h * sizeof(unsigned char));
80
if ((!ps->image)||(!ps->image_buf)) {
81
reportError("Problem allocating memory for image %ix%i", w, h);
82
return DICT_ERROR_MALLOC;
85
if (TIFFReadRGBAImage(tif, w, h, (uint32_t*)ps->image_buf, 0)) {
86
dictReduceImage(ps, ps->image_buf, w, h);
92
return DICT_ERROR_IMAGE;
93
#endif /* DICT_TIFF_SUPPORT */
96
int dictImageLoadImage(DICTContext ps, const char *name) {
97
#ifdef DICT_TIFF_SUPPORT
98
TIFF* tif = TIFFOpen(name, "r");
99
if (!tif) return DICT_ERROR_IMAGE;
101
if (TIFFReadRGBAImage(tif, ps->width, ps->height, (uint32_t*)ps->image_buf, 0)) {
102
dictReduceImage(ps, ps->image_buf, ps->width, ps->height);
107
return DICT_ERROR_IMAGE;
108
#endif /* DICT_TIFF_SUPPORT */