Leptonica 1.82.0
Image processing and image analysis suite
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
70/*---------------------------------------------------------------------*
71 * Pixacc creation, destruction *
72 *---------------------------------------------------------------------*/
91PIXACC *
92pixaccCreate(l_int32 w,
93 l_int32 h,
94 l_int32 negflag)
95{
96PIXACC *pixacc;
97
98 PROCNAME("pixaccCreate");
99
100 pixacc = (PIXACC *)LEPT_CALLOC(1, sizeof(PIXACC));
101 pixacc->w = w;
102 pixacc->h = h;
103
104 if ((pixacc->pix = pixCreate(w, h, 32)) == NULL) {
105 pixaccDestroy(&pixacc);
106 return (PIXACC *)ERROR_PTR("pix not made", procName, NULL);
107 }
108
109 if (negflag) {
110 pixacc->offset = 0x40000000;
111 pixSetAllArbitrary(pixacc->pix, pixacc->offset);
112 }
113
114 return pixacc;
115}
116
117
131PIXACC *
133 l_int32 negflag)
134{
135l_int32 w, h;
136PIXACC *pixacc;
137
138 PROCNAME("pixaccCreateFromPix");
139
140 if (!pix)
141 return (PIXACC *)ERROR_PTR("pix not defined", procName, NULL);
142
143 pixGetDimensions(pix, &w, &h, NULL);
144 pixacc = pixaccCreate(w, h, negflag);
145 pixaccAdd(pixacc, pix);
146 return pixacc;
147}
148
149
161void
163{
164PIXACC *pixacc;
165
166 PROCNAME("pixaccDestroy");
167
168 if (ppixacc == NULL) {
169 L_WARNING("ptr address is NULL!", procName);
170 return;
171 }
172
173 if ((pixacc = *ppixacc) == NULL)
174 return;
175
176 pixDestroy(&pixacc->pix);
177 LEPT_FREE(pixacc);
178 *ppixacc = NULL;
179}
180
181
182/*---------------------------------------------------------------------*
183 * Pixacc finalization *
184 *---------------------------------------------------------------------*/
192PIX *
194 l_int32 outdepth)
195{
196 PROCNAME("pixaccFinal");
197
198 if (!pixacc)
199 return (PIX *)ERROR_PTR("pixacc not defined", procName, NULL);
200
201 return pixFinalAccumulate(pixaccGetPix(pixacc), pixaccGetOffset(pixacc),
202 outdepth);
203}
204
205
206/*---------------------------------------------------------------------*
207 * Pixacc accessors *
208 *---------------------------------------------------------------------*/
215PIX *
217{
218 PROCNAME("pixaccGetPix");
219
220 if (!pixacc)
221 return (PIX *)ERROR_PTR("pixacc not defined", procName, NULL);
222 return pixacc->pix;
223}
224
225
232l_int32
234{
235 PROCNAME("pixaccGetOffset");
236
237 if (!pixacc)
238 return ERROR_INT("pixacc not defined", procName, -1);
239 return pixacc->offset;
240}
241
242
243/*---------------------------------------------------------------------*
244 * Pixacc accumulators *
245 *---------------------------------------------------------------------*/
253l_ok
255 PIX *pix)
256{
257 PROCNAME("pixaccAdd");
258
259 if (!pixacc)
260 return ERROR_INT("pixacc not defined", procName, 1);
261 if (!pix)
262 return ERROR_INT("pix not defined", procName, 1);
263 pixAccumulate(pixaccGetPix(pixacc), pix, L_ARITH_ADD);
264 return 0;
265}
266
267
275l_ok
277 PIX *pix)
278{
279 PROCNAME("pixaccSubtract");
280
281 if (!pixacc)
282 return ERROR_INT("pixacc not defined", procName, 1);
283 if (!pix)
284 return ERROR_INT("pix not defined", procName, 1);
285 pixAccumulate(pixaccGetPix(pixacc), pix, L_ARITH_SUBTRACT);
286 return 0;
287}
288
289
297l_ok
299 l_float32 factor)
300{
301 PROCNAME("pixaccMultConst");
302
303 if (!pixacc)
304 return ERROR_INT("pixacc not defined", procName, 1);
305 pixMultConstAccumulate(pixaccGetPix(pixacc), factor,
306 pixaccGetOffset(pixacc));
307 return 0;
308}
309
310
325l_ok
327 PIX *pix,
328 l_float32 factor)
329{
330l_int32 w, h, d, negflag;
331PIX *pixt;
332PIXACC *pacct;
333
334 PROCNAME("pixaccMultConstAccumulate");
335
336 if (!pixacc)
337 return ERROR_INT("pixacc not defined", procName, 1);
338 if (!pix)
339 return ERROR_INT("pix not defined", procName, 1);
340
341 if (factor == 0.0) return 0;
342
343 pixGetDimensions(pix, &w, &h, &d);
344 negflag = (factor > 0.0) ? 0 : 1;
345 pacct = pixaccCreate(w, h, negflag);
346 pixaccAdd(pacct, pix);
347 pixaccMultConst(pacct, factor);
348 pixt = pixaccFinal(pacct, d);
349 pixaccAdd(pixacc, pixt);
350
351 pixaccDestroy(&pacct);
352 pixDestroy(&pixt);
353 return 0;
354}
void pixDestroy(PIX **ppix)
pixDestroy()
Definition: pix1.c:621
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
Definition: pix1.c:1113
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
Definition: pix1.c:315
l_ok pixSetAllArbitrary(PIX *pix, l_uint32 val)
pixSetAllArbitrary()
Definition: pix2.c:951
PIX * pixaccGetPix(PIXACC *pixacc)
pixaccGetPix()
Definition: pixacc.c:216
PIXACC * pixaccCreate(l_int32 w, l_int32 h, l_int32 negflag)
pixaccCreate()
Definition: pixacc.c:92
l_ok pixaccSubtract(PIXACC *pixacc, PIX *pix)
pixaccSubtract()
Definition: pixacc.c:276
l_ok pixaccAdd(PIXACC *pixacc, PIX *pix)
pixaccAdd()
Definition: pixacc.c:254
l_ok pixaccMultConstAccumulate(PIXACC *pixacc, PIX *pix, l_float32 factor)
pixaccMultConstAccumulate()
Definition: pixacc.c:326
l_int32 pixaccGetOffset(PIXACC *pixacc)
pixaccGetOffset()
Definition: pixacc.c:233
void pixaccDestroy(PIXACC **ppixacc)
pixaccDestroy()
Definition: pixacc.c:162
PIX * pixaccFinal(PIXACC *pixacc, l_int32 outdepth)
pixaccFinal()
Definition: pixacc.c:193
PIXACC * pixaccCreateFromPix(PIX *pix, l_int32 negflag)
pixaccCreateFromPix()
Definition: pixacc.c:132
l_ok pixaccMultConst(PIXACC *pixacc, l_float32 factor)
pixaccMultConst()
Definition: pixacc.c:298
l_ok pixMultConstAccumulate(PIX *pixs, l_float32 factor, l_uint32 offset)
pixMultConstAccumulate()
Definition: pixarith.c:916
PIX * pixFinalAccumulate(PIX *pixs, l_uint32 offset, l_int32 depth)
pixFinalAccumulate()
Definition: pixarith.c:683
l_ok pixAccumulate(PIX *pixd, PIX *pixs, l_int32 op)
pixAccumulate()
Definition: pixarith.c:817
Definition: pix.h:139
Definition: pix.h:544
l_int32 offset
Definition: pix.h:547
l_int32 h
Definition: pix.h:546
l_int32 w
Definition: pix.h:545
struct Pix * pix
Definition: pix.h:549