Leptonica 1.85.0
Image processing and image analysis suite
Loading...
Searching...
No Matches
pixacc.c
Go to the documentation of this file.
1/*====================================================================*
2 - Copyright (C) 2001 Leptonica. All rights reserved.
3 -
4 - Redistribution and use in source and binary forms, with or without
5 - modification, are permitted provided that the following conditions
6 - are met:
7 - 1. Redistributions of source code must retain the above copyright
8 - notice, this list of conditions and the following disclaimer.
9 - 2. Redistributions in binary form must reproduce the above
10 - copyright notice, this list of conditions and the following
11 - disclaimer in the documentation and/or other materials
12 - provided with the distribution.
13 -
14 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *====================================================================*/
26
64#ifdef HAVE_CONFIG_H
65#include <config_auto.h>
66#endif /* HAVE_CONFIG_H */
67
68#include "allheaders.h"
69#include "pix_internal.h"
70
71/*---------------------------------------------------------------------*
72 * Pixacc creation, destruction *
73 *---------------------------------------------------------------------*/
92PIXACC *
93pixaccCreate(l_int32 w,
94 l_int32 h,
95 l_int32 negflag)
96{
97PIXACC *pixacc;
98
99 pixacc = (PIXACC *)LEPT_CALLOC(1, sizeof(PIXACC));
100 pixacc->w = w;
101 pixacc->h = h;
102
103 if ((pixacc->pix = pixCreate(w, h, 32)) == NULL) {
104 pixaccDestroy(&pixacc);
105 return (PIXACC *)ERROR_PTR("pix not made", __func__, NULL);
106 }
107
108 if (negflag) {
109 pixacc->offset = 0x40000000;
110 pixSetAllArbitrary(pixacc->pix, pixacc->offset);
111 }
112
113 return pixacc;
114}
115
116
130PIXACC *
132 l_int32 negflag)
133{
134l_int32 w, h;
135PIXACC *pixacc;
136
137 if (!pix)
138 return (PIXACC *)ERROR_PTR("pix not defined", __func__, NULL);
139
140 pixGetDimensions(pix, &w, &h, NULL);
141 pixacc = pixaccCreate(w, h, negflag);
142 pixaccAdd(pixacc, pix);
143 return pixacc;
144}
145
146
158void
160{
161PIXACC *pixacc;
162
163 if (ppixacc == NULL) {
164 L_WARNING("ptr address is NULL!", __func__);
165 return;
166 }
167
168 if ((pixacc = *ppixacc) == NULL)
169 return;
170
171 pixDestroy(&pixacc->pix);
172 LEPT_FREE(pixacc);
173 *ppixacc = NULL;
174}
175
176
177/*---------------------------------------------------------------------*
178 * Pixacc finalization *
179 *---------------------------------------------------------------------*/
187PIX *
189 l_int32 outdepth)
190{
191 if (!pixacc)
192 return (PIX *)ERROR_PTR("pixacc not defined", __func__, NULL);
193
194 return pixFinalAccumulate(pixaccGetPix(pixacc), pixaccGetOffset(pixacc),
195 outdepth);
196}
197
198
199/*---------------------------------------------------------------------*
200 * Pixacc accessors *
201 *---------------------------------------------------------------------*/
208PIX *
210{
211 if (!pixacc)
212 return (PIX *)ERROR_PTR("pixacc not defined", __func__, NULL);
213 return pixacc->pix;
214}
215
216
223l_int32
225{
226 if (!pixacc)
227 return ERROR_INT("pixacc not defined", __func__, -1);
228 return pixacc->offset;
229}
230
231
232/*---------------------------------------------------------------------*
233 * Pixacc accumulators *
234 *---------------------------------------------------------------------*/
242l_ok
244 PIX *pix)
245{
246 if (!pixacc)
247 return ERROR_INT("pixacc not defined", __func__, 1);
248 if (!pix)
249 return ERROR_INT("pix not defined", __func__, 1);
250 pixAccumulate(pixaccGetPix(pixacc), pix, L_ARITH_ADD);
251 return 0;
252}
253
254
262l_ok
264 PIX *pix)
265{
266 if (!pixacc)
267 return ERROR_INT("pixacc not defined", __func__, 1);
268 if (!pix)
269 return ERROR_INT("pix not defined", __func__, 1);
270 pixAccumulate(pixaccGetPix(pixacc), pix, L_ARITH_SUBTRACT);
271 return 0;
272}
273
274
282l_ok
284 l_float32 factor)
285{
286 if (!pixacc)
287 return ERROR_INT("pixacc not defined", __func__, 1);
288 pixMultConstAccumulate(pixaccGetPix(pixacc), factor,
289 pixaccGetOffset(pixacc));
290 return 0;
291}
292
293
308l_ok
310 PIX *pix,
311 l_float32 factor)
312{
313l_int32 w, h, d, negflag;
314PIX *pixt;
315PIXACC *pacct;
316
317 if (!pixacc)
318 return ERROR_INT("pixacc not defined", __func__, 1);
319 if (!pix)
320 return ERROR_INT("pix not defined", __func__, 1);
321
322 if (factor == 0.0) return 0;
323
324 pixGetDimensions(pix, &w, &h, &d);
325 negflag = (factor > 0.0) ? 0 : 1;
326 pacct = pixaccCreate(w, h, negflag);
327 pixaccAdd(pacct, pix);
328 pixaccMultConst(pacct, factor);
329 pixt = pixaccFinal(pacct, d);
330 pixaccAdd(pixacc, pixt);
331
332 pixaccDestroy(&pacct);
333 pixDestroy(&pixt);
334 return 0;
335}
PIX * pixaccGetPix(PIXACC *pixacc)
pixaccGetPix()
Definition pixacc.c:209
PIXACC * pixaccCreate(l_int32 w, l_int32 h, l_int32 negflag)
pixaccCreate()
Definition pixacc.c:93
l_ok pixaccSubtract(PIXACC *pixacc, PIX *pix)
pixaccSubtract()
Definition pixacc.c:263
l_ok pixaccAdd(PIXACC *pixacc, PIX *pix)
pixaccAdd()
Definition pixacc.c:243
l_ok pixaccMultConstAccumulate(PIXACC *pixacc, PIX *pix, l_float32 factor)
pixaccMultConstAccumulate()
Definition pixacc.c:309
l_int32 pixaccGetOffset(PIXACC *pixacc)
pixaccGetOffset()
Definition pixacc.c:224
void pixaccDestroy(PIXACC **ppixacc)
pixaccDestroy()
Definition pixacc.c:159
PIX * pixaccFinal(PIXACC *pixacc, l_int32 outdepth)
pixaccFinal()
Definition pixacc.c:188
PIXACC * pixaccCreateFromPix(PIX *pix, l_int32 negflag)
pixaccCreateFromPix()
Definition pixacc.c:131
l_ok pixaccMultConst(PIXACC *pixacc, l_float32 factor)
pixaccMultConst()
Definition pixacc.c:283
l_int32 offset
l_int32 h
l_int32 w
struct Pix * pix