CR2RE Pipeline Reference Manual 1.6.7
hdrl_cat_apio.c
1/*
2 * This file is part of the HDRL
3 * Copyright (C) 2017 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include "hdrl_cat_apio.h"
21
22
23/*** DEFINES ***/
24#define MAXBL 250000
25
26
27/*----------------------------------------------------------------------------*/
35/*----------------------------------------------------------------------------*/
36
39/* ---------------------------------------------------------------------------*/
53/* ---------------------------------------------------------------------------*/
54void hdrl_apinit(ap_t *ap) {
55
56 /* max possible parents */
57 cpl_size maxpa = ap->lsiz / 2;
58
59 ap->lastline = cpl_calloc(ap->lsiz + 1, sizeof(*ap->lastline));
60 ap->maxip = 0;
61 ap->maxpa = maxpa;
62 ap->pstack = cpl_malloc(maxpa * sizeof(*ap->pstack));
63 ap->parent = cpl_malloc(maxpa * sizeof(*ap->parent));
64
65 for (cpl_size i = 0; i < maxpa; i++) {
66 ap->pstack[i] = i;
67 ap->parent[i].pnop = -1; /* mark all parents inactive */
68 ap->parent[i].pnbp = -1; /* mark all parents inactive */
69 }
70
71 ap->ipstack = 1;
72 ap->maxbl = MAXBL;
73 ap->bstack = cpl_malloc(ap->maxbl * sizeof(*ap->bstack));
74 ap->blink = cpl_malloc(ap->maxbl * sizeof(*ap->blink));
75 ap->plessey = cpl_malloc(ap->maxbl * sizeof(*ap->plessey));
76
77 for (cpl_size i = 0; i < MAXBL; i++) {
78 ap->bstack[i] = i;
79 }
80
81 ap->ibstack = 2; /* block 1 will get overwritten; don't use it */
82 ap->nimages = 0;
83
84 /* set up exponential areal-profile levels: */
85 ap->areal[0] = 1;
86 cpl_size maxAreal = 8;
87 for (cpl_size i = 1; i < maxAreal; i++) {
88 ap->areal[i] = ap->areal[i - 1] * 2;
89 }
90
91 /* allocate some space for a processing array */
92 ap->npl = ap->lsiz;
93 ap->npl_pix = 0;
94 ap->plarray = cpl_malloc(ap->npl * sizeof(*ap->plarray));
95
96 /* set these to null values as you may not need the background structure */
97 ap->backmap.nby = -1;
98 ap->backmap.bvals = NULL;
99
100 /* Initialise some info about the input images */
101 ap->indata = NULL;
102 ap->confdata = NULL;
103}
104
105/* ---------------------------------------------------------------------------*/
119/* ---------------------------------------------------------------------------*/
120void hdrl_apreinit(ap_t *ap) {
121
122 for (cpl_size i = 0; i < ap->lsiz + 1; i++) {
123 ap->lastline[i] = 0;
124 }
125
126 ap->maxip = 0;
127
128 for (cpl_size i = 0; i < ap->maxpa; i++) {
129 ap->pstack[i] = i;
130 ap->parent[i].pnop = -1; /* mark all parents inactive */
131 ap->parent[i].pnbp = -1; /* mark all parents inactive */
132 }
133
134 ap->ipstack = 1;
135 ap->ibstack = 2; /* block 1 will get overwritten; don't use it */
136 ap->nimages = 0;
137 ap->npl_pix = 0;
138}
139
140/* ---------------------------------------------------------------------------*/
152/* ---------------------------------------------------------------------------*/
153void hdrl_apclose(ap_t *ap) {
154
155 if (ap->lastline) {cpl_free(ap->lastline); ap->lastline = NULL;}
156 if (ap->pstack ) {cpl_free(ap->pstack ); ap->pstack = NULL;}
157 if (ap->parent ) {cpl_free(ap->parent ); ap->parent = NULL;}
158 if (ap->bstack ) {cpl_free(ap->bstack ); ap->bstack = NULL;}
159 if (ap->blink ) {cpl_free(ap->blink ); ap->blink = NULL;}
160 if (ap->plessey ) {cpl_free(ap->plessey ); ap->plessey = NULL;}
161 if (ap->plarray ) {cpl_free(ap->plarray ); ap->plarray = NULL;}
162
163 if (ap->backmap.bvals) {
164
165 for (cpl_size i = 0; i < ap->backmap.nby; i++) {
166
167 if (ap->backmap.bvals[i]) {
168 cpl_free(ap->backmap.bvals[i]);
169 ap->backmap.bvals[i] = NULL;
170 }
171 }
172
173 cpl_free(ap->backmap.bvals);
174 ap->backmap.bvals = NULL;
175 }
176}
177
void hdrl_apinit(ap_t *ap)
Initialize the ap structure.
Definition: hdrl_cat_apio.c:54
void hdrl_apreinit(ap_t *ap)
Re-initialize the ap structure.
void hdrl_apclose(ap_t *ap)
Close ap structure.