4 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2014, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
33 #include "cachemodel_manager.h"
34 #include "faixbox_manager.h"
35 #include "opj_inttypes.h"
38 #include "fcgi_stdio.h"
39 #define logstream FCGI_stdout
41 #define FCGI_stdout stdout
42 #define FCGI_stderr stderr
43 #define logstream stderr
47 cachemodellist_param_t * gene_cachemodellist(void)
49 cachemodellist_param_t *cachemodellist;
51 cachemodellist = (cachemodellist_param_t *)opj_malloc(sizeof(
52 cachemodellist_param_t));
54 cachemodellist->first = NULL;
55 cachemodellist->last = NULL;
57 return cachemodellist;
60 cachemodel_param_t * gene_cachemodel(cachemodellist_param_t *cachemodellist,
61 target_param_t *target, OPJ_BOOL reqJPP)
63 cachemodel_param_t *cachemodel;
64 faixbox_param_t *tilepart;
65 faixbox_param_t *precpacket;
70 cachemodel = (cachemodel_param_t *)opj_malloc(sizeof(cachemodel_param_t));
72 refer_target(target, &cachemodel->target);
75 if (target->jppstream) {
76 cachemodel->jppstream = OPJ_TRUE;
78 cachemodel->jppstream = OPJ_FALSE;
81 if (target->jptstream) {
82 cachemodel->jppstream = OPJ_FALSE;
84 cachemodel->jppstream = OPJ_TRUE;
88 cachemodel->mhead_model = OPJ_FALSE;
90 tilepart = target->codeidx->tilepart;
91 numOftiles = get_m(tilepart);
92 numOfelem = get_nmax(tilepart) * numOftiles;
93 cachemodel->tp_model = (OPJ_BOOL *)opj_calloc(1, numOfelem * sizeof(OPJ_BOOL));
94 cachemodel->th_model = (OPJ_BOOL *)opj_calloc(1, numOftiles * sizeof(OPJ_BOOL));
95 cachemodel->pp_model = (OPJ_BOOL **)opj_malloc(target->codeidx->SIZ.Csiz *
97 for (i = 0; i < target->codeidx->SIZ.Csiz; i++) {
98 precpacket = target->codeidx->precpacket[i];
99 cachemodel->pp_model[i] = (OPJ_BOOL *)opj_calloc(1,
100 get_nmax(precpacket) * get_m(precpacket) * sizeof(OPJ_BOOL));
102 cachemodel->next = NULL;
104 if (cachemodellist) {
105 if (cachemodellist->first) { /* there are one or more entries */
106 cachemodellist->last->next = cachemodel;
107 } else { /* first entry */
108 cachemodellist->first = cachemodel;
110 cachemodellist->last = cachemodel;
114 fprintf(logstream, "local log: cachemodel generated\n");
120 void print_cachemodel(cachemodel_param_t cachemodel)
122 target_param_t *target;
123 Byte8_t TPnum; /* num of tile parts in each tile */
124 Byte8_t Pmax; /* max num of packets per tile */
126 int n; /* FIXME: Is this large enough ? */
128 target = cachemodel.target;
130 fprintf(logstream, "target: %s\n", target->targetname);
131 fprintf(logstream, "\t main header model: %d\n", cachemodel.mhead_model);
133 fprintf(logstream, "\t tile part model:\n");
134 TPnum = get_nmax(target->codeidx->tilepart);
136 for (i = 0, n = 0; i < target->codeidx->SIZ.YTnum; i++) {
137 for (j = 0; j < target->codeidx->SIZ.XTnum; j++) {
138 for (k = 0; k < TPnum; k++) {
139 fprintf(logstream, "%d", cachemodel.tp_model[n++]);
141 fprintf(logstream, " ");
143 fprintf(logstream, "\n");
146 fprintf(logstream, "\t tile header and precinct packet model:\n");
147 for (i = 0; i < target->codeidx->SIZ.XTnum * target->codeidx->SIZ.YTnum; i++) {
148 fprintf(logstream, "\t tile.%" PRIu64 " %d\n", i, cachemodel.th_model[i]);
149 for (j = 0; j < target->codeidx->SIZ.Csiz; j++) {
150 fprintf(logstream, "\t compo.%" PRIu64 ": ", j);
151 Pmax = get_nmax(target->codeidx->precpacket[j]);
152 for (k = 0; k < Pmax; k++) {
153 fprintf(logstream, "%d", cachemodel.pp_model[j][i * Pmax + k]);
155 fprintf(logstream, "\n");
160 cachemodel_param_t * search_cachemodel(target_param_t *target,
161 cachemodellist_param_t *cachemodellist)
163 cachemodel_param_t *foundcachemodel;
165 foundcachemodel = cachemodellist->first;
167 while (foundcachemodel != NULL) {
169 if (foundcachemodel->target == target) {
170 return foundcachemodel;
173 foundcachemodel = foundcachemodel->next;
178 void delete_cachemodellist(cachemodellist_param_t **cachemodellist)
180 cachemodel_param_t *cachemodelPtr, *cachemodelNext;
182 cachemodelPtr = (*cachemodellist)->first;
183 while (cachemodelPtr != NULL) {
184 cachemodelNext = cachemodelPtr->next;
185 delete_cachemodel(&cachemodelPtr);
186 cachemodelPtr = cachemodelNext;
188 opj_free(*cachemodellist);
191 void delete_cachemodel(cachemodel_param_t **cachemodel)
195 unrefer_target((*cachemodel)->target);
197 opj_free((*cachemodel)->tp_model);
198 opj_free((*cachemodel)->th_model);
200 for (i = 0; i < (*cachemodel)->target->codeidx->SIZ.Csiz; i++) {
201 opj_free((*cachemodel)->pp_model[i]);
203 opj_free((*cachemodel)->pp_model);
206 fprintf(logstream, "local log: cachemodel deleted\n");
208 opj_free(*cachemodel);
211 OPJ_BOOL is_allsent(cachemodel_param_t cachemodel)
213 target_param_t *target;
214 Byte8_t TPnum; /* num of tile parts in each tile */
215 Byte8_t Pmax; /* max num of packets per tile */
217 int n; /* FIXME: is this large enough ? */
219 target = cachemodel.target;
221 if (!cachemodel.mhead_model) {
225 TPnum = get_nmax(target->codeidx->tilepart);
227 if (cachemodel.jppstream) {
228 for (i = 0; i < target->codeidx->SIZ.XTnum * target->codeidx->SIZ.YTnum; i++) {
229 if (!cachemodel.th_model[i]) {
233 for (j = 0; j < target->codeidx->SIZ.Csiz; j++) {
234 Pmax = get_nmax(target->codeidx->precpacket[j]);
235 for (k = 0; k < Pmax; k++)
236 if (!cachemodel.pp_model[j][i * Pmax + k]) {
243 for (i = 0, n = 0; i < target->codeidx->SIZ.YTnum; i++)
244 for (j = 0; j < target->codeidx->SIZ.XTnum; j++)
245 for (k = 0; k < TPnum; k++)
246 if (!cachemodel.tp_model[n++]) {