1 /*########################################################################
3 * Copyright(C) 2002-2007. All Rights Reserved.
5 * Authors: Shivang Patel
8 * Changes: jdh -> Added support for ImageMagick that enables
9 * to export files to more than 40 formats.
10 * This is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2, or (at your option) any later
15 * This is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * You should have received a copy of the GNU General Public License with
21 * the fvs source package as the
22 * file COPYING. If not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place - Suite 330, Boston, MA
25 ########################################################################*/
31 #include "floatfield.h"
34 A fingerprint floating point field structure.
36 typedef struct iFvsFloatField_t
38 FvsFloat_t
*pimg
; /* floating point field array */
39 FvsInt_t w
; /* width of field */
40 FvsInt_t h
; /* height of field */
41 FvsInt_t pitch
; /* pitch */
45 FvsFloatField_t
FloatFieldCreate()
47 iFvsFloatField_t
* p
= NULL
;
48 p
= (FvsFloatField_t
)malloc(sizeof(iFvsFloatField_t
));
58 return (FvsFloatField_t
)p
;
62 void FloatFieldDestroy(FvsFloatField_t field
)
64 iFvsFloatField_t
* p
= NULL
;
70 (void)FloatFieldSetSize(field
, 0, 0);
75 FvsError_t
FloatFieldSetSize(FvsFloatField_t img
, const FvsInt_t width
, const FvsInt_t height
)
77 iFvsFloatField_t
* field
= (iFvsFloatField_t
*)img
;
78 FvsError_t nRet
= FvsOK
;
79 FvsInt_t newsize
= (FvsInt_t
)(width
*height
*sizeof(FvsFloat_t
));
81 /* special case for zero size */
84 if (field
->pimg
!=NULL
)
95 if ((FvsInt_t
)(field
->h
*field
->w
*sizeof(FvsFloat_t
)) != newsize
)
101 /* This allocates the amount of memory need for the field structure */
102 field
->pimg
= (FvsFloat_t
*)malloc((size_t)newsize
);
105 if (field
->pimg
== NULL
)
111 field
->pitch
= width
;
117 FvsError_t
FloatFieldCopy(FvsFloatField_t destination
, const FvsFloatField_t source
)
119 iFvsFloatField_t
* dest
= (iFvsFloatField_t
*)destination
;
120 iFvsFloatField_t
* src
= (iFvsFloatField_t
*)source
;
121 FvsError_t nRet
= FvsOK
;
123 nRet
= FloatFieldSetSize(dest
, src
->w
, src
->h
);
126 memcpy(dest
->pimg
, src
->pimg
, src
->h
*src
->w
*sizeof(FvsFloat_t
));
132 FvsError_t
FloatFieldClear(FvsFloatField_t img
)
134 return FloatFieldFlood(img
, 0.0);
138 FvsError_t
FloatFieldFlood(FvsFloatField_t img
, const FvsFloat_t value
)
140 iFvsFloatField_t
* field
= (iFvsFloatField_t
*)img
;
141 FvsError_t nRet
= FvsOK
;
143 if (field
->pimg
!=NULL
)
145 for (i
=0; i
<field
->h
*field
->w
; i
++)
146 field
->pimg
[i
] = value
;
152 /* set a pixel value in the picture */
153 void FloatFieldSetValue(FvsFloatField_t img
, const FvsInt_t x
, const FvsInt_t y
, const FvsFloat_t val
)
155 iFvsFloatField_t
* field
= (iFvsFloatField_t
*)img
;
156 int address
= y
* field
->w
+ x
;
157 field
->pimg
[address
] = val
;
161 /* This function returns the pixel for the x and y value */
162 FvsFloat_t
FloatFieldGetValue(FvsFloatField_t img
, const FvsInt_t x
, const FvsInt_t y
)
164 iFvsFloatField_t
* field
= (iFvsFloatField_t
*)img
;
165 /* position in array */
166 int address
= y
* field
->pitch
+ x
;
167 return field
->pimg
[address
];
171 /* returns a pointer to the field buffer */
172 FvsFloat_t
* FloatFieldGetBuffer(FvsFloatField_t img
)
174 iFvsFloatField_t
* field
= (iFvsFloatField_t
*)img
;
179 /* retrieve width and height */
180 FvsInt_t
FloatFieldGetWidth(const FvsFloatField_t img
)
182 iFvsFloatField_t
* field
= (iFvsFloatField_t
*)img
;
187 FvsInt_t
FloatFieldGetHeight(const FvsFloatField_t img
)
189 iFvsFloatField_t
* field
= (iFvsFloatField_t
*)img
;
194 /* get the pitch pixel(x,y) pos is at x + y * pitch */
195 FvsInt_t
FloatFieldGetPitch(const FvsFloatField_t img
)
197 iFvsFloatField_t
* field
= (iFvsFloatField_t
*)img
;