Make clang build as silent as possible
[fvs_assignment_project.git] / floatfield.c
bloba47449d3b98a930892805f9e5d19b2362b3cc32e
1 /*########################################################################
3 * Copyright(C) 2002-2007. All Rights Reserved.
5 * Authors: Shivang Patel
6 * Jaap de Haan(jdh)
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
13 * version.
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
18 * for more details.
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
24 * 02111-1307, USA.
25 ########################################################################*/
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
31 #include "floatfield.h"
33 /*!
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 */
42 } iFvsFloatField_t;
45 FvsFloatField_t FloatFieldCreate()
47 iFvsFloatField_t* p = NULL;
48 p = (FvsFloatField_t)malloc(sizeof(iFvsFloatField_t));
50 if (p!=NULL)
52 p->h = 0;
53 p->w = 0;
54 p->pitch = 0;
55 p->pimg = NULL;
58 return (FvsFloatField_t)p;
62 void FloatFieldDestroy(FvsFloatField_t field)
64 iFvsFloatField_t* p = NULL;
66 if (field==NULL)
67 return;
69 p = field;
70 (void)FloatFieldSetSize(field, 0, 0);
71 free(p);
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 */
82 if (newsize==0)
84 if (field->pimg!=NULL)
86 free(field->pimg);
87 field->pimg = NULL;
88 field->w = 0;
89 field->h = 0;
90 field->pitch = 0;
92 return FvsOK;
95 if ((FvsInt_t)(field->h*field->w*sizeof(FvsFloat_t)) != newsize)
97 free(field->pimg);
98 field->w = 0;
99 field->h = 0;
100 field->pitch = 0;
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)
106 nRet = FvsMemory;
107 else
109 field->h = height;
110 field->w = width;
111 field->pitch = width;
113 return nRet;
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);
125 if (nRet==FvsOK)
126 memcpy(dest->pimg, src->pimg, src->h*src->w*sizeof(FvsFloat_t));
128 return nRet;
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;
142 FvsInt_t i;
143 if (field->pimg!=NULL)
145 for (i=0; i<field->h*field->w; i++)
146 field->pimg[i] = value;
148 return nRet;
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;
175 return field->pimg;
179 /* retrieve width and height */
180 FvsInt_t FloatFieldGetWidth(const FvsFloatField_t img)
182 iFvsFloatField_t* field = (iFvsFloatField_t*)img;
183 return field->w;
187 FvsInt_t FloatFieldGetHeight(const FvsFloatField_t img)
189 iFvsFloatField_t* field = (iFvsFloatField_t*)img;
190 return field->h;
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;
198 return field->pitch;