OLD | NEW |
1 /* | 1 /* |
2 * The copyright in this software is being made available under the 2-clauses | 2 * The copyright in this software is being made available under the 2-clauses |
3 * BSD License, included below. This software may be subject to other third | 3 * BSD License, included below. This software may be subject to other third |
4 * party and contributor rights, including patent rights, and no such rights | 4 * party and contributor rights, including patent rights, and no such rights |
5 * are granted under this license. | 5 * are granted under this license. |
6 * | 6 * |
7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium | 7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium |
8 * Copyright (c) 2002-2014, Professor Benoit Macq | 8 * Copyright (c) 2002-2014, Professor Benoit Macq |
9 * Copyright (c) 2001-2003, David Janssens | 9 * Copyright (c) 2001-2003, David Janssens |
10 * Copyright (c) 2002-2003, Yannick Verschueren | 10 * Copyright (c) 2002-2003, Yannick Verschueren |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 OPJ_INT32 nplv[32]; | 50 OPJ_INT32 nplv[32]; |
51 opj_tgt_node_t *node = 00; | 51 opj_tgt_node_t *node = 00; |
52 opj_tgt_node_t *l_parent_node = 00; | 52 opj_tgt_node_t *l_parent_node = 00; |
53 opj_tgt_node_t *l_parent_node0 = 00; | 53 opj_tgt_node_t *l_parent_node0 = 00; |
54 opj_tgt_tree_t *tree = 00; | 54 opj_tgt_tree_t *tree = 00; |
55 OPJ_UINT32 i; | 55 OPJ_UINT32 i; |
56 OPJ_INT32 j,k; | 56 OPJ_INT32 j,k; |
57 OPJ_UINT32 numlvls; | 57 OPJ_UINT32 numlvls; |
58 OPJ_UINT32 n; | 58 OPJ_UINT32 n; |
59 | 59 |
60 tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t)); | 60 tree = (opj_tgt_tree_t *) opj_calloc(1,sizeof(opj_tgt_tree_t)); |
61 if(!tree) { | 61 if(!tree) { |
62 fprintf(stderr, "ERROR in tgt_create while allocating tree\n"); | 62 fprintf(stderr, "ERROR in tgt_create while allocating tree\n"); |
63 return 00; | 63 return 00; |
64 } | 64 } |
65 memset(tree,0,sizeof(opj_tgt_tree_t)); | |
66 | 65 |
67 tree->numleafsh = numleafsh; | 66 tree->numleafsh = numleafsh; |
68 tree->numleafsv = numleafsv; | 67 tree->numleafsv = numleafsv; |
69 | 68 |
70 numlvls = 0; | 69 numlvls = 0; |
71 nplh[0] = (OPJ_INT32)numleafsh; | 70 nplh[0] = (OPJ_INT32)numleafsh; |
72 nplv[0] = (OPJ_INT32)numleafsv; | 71 nplv[0] = (OPJ_INT32)numleafsv; |
73 tree->numnodes = 0; | 72 tree->numnodes = 0; |
74 do { | 73 do { |
75 n = (OPJ_UINT32)(nplh[numlvls] * nplv[numlvls]); | 74 n = (OPJ_UINT32)(nplh[numlvls] * nplv[numlvls]); |
76 nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2; | 75 nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2; |
77 nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2; | 76 nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2; |
78 tree->numnodes += n; | 77 tree->numnodes += n; |
79 ++numlvls; | 78 ++numlvls; |
80 } while (n > 1); | 79 } while (n > 1); |
81 | 80 |
82 /* ADD */ | 81 /* ADD */ |
83 if (tree->numnodes == 0) { | 82 if (tree->numnodes == 0) { |
84 opj_free(tree); | 83 opj_free(tree); |
85 fprintf(stderr, "WARNING in tgt_create tree->numnodes == 0, no t
ree created.\n"); | 84 fprintf(stderr, "WARNING in tgt_create tree->numnodes == 0, no t
ree created.\n"); |
86 return 00; | 85 return 00; |
87 } | 86 } |
88 | 87 |
89 tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tg
t_node_t)); | 88 tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tg
t_node_t)); |
90 if(!tree->nodes) { | 89 if(!tree->nodes) { |
91 fprintf(stderr, "ERROR in tgt_create while allocating node of th
e tree\n"); | 90 fprintf(stderr, "ERROR in tgt_create while allocating node of th
e tree\n"); |
92 opj_free(tree); | 91 opj_free(tree); |
93 return 00; | 92 return 00; |
94 } | 93 } |
95 memset(tree->nodes,0,tree->numnodes * sizeof(opj_tgt_node_t)); | |
96 tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t); | 94 tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t); |
97 | 95 |
98 node = tree->nodes; | 96 node = tree->nodes; |
99 l_parent_node = &tree->nodes[tree->numleafsh * tree->numleafsv]; | 97 l_parent_node = &tree->nodes[tree->numleafsh * tree->numleafsv]; |
100 l_parent_node0 = l_parent_node; | 98 l_parent_node0 = l_parent_node; |
101 | 99 |
102 for (i = 0; i < numlvls - 1; ++i) { | 100 for (i = 0; i < numlvls - 1; ++i) { |
103 for (j = 0; j < nplv[i]; ++j) { | 101 for (j = 0; j < nplv[i]; ++j) { |
104 k = nplh[i]; | 102 k = nplh[i]; |
105 while (--k >= 0) { | 103 while (--k >= 0) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 326 } |
329 node->low = low; | 327 node->low = low; |
330 if (stkptr == stk) { | 328 if (stkptr == stk) { |
331 break; | 329 break; |
332 } | 330 } |
333 node = *--stkptr; | 331 node = *--stkptr; |
334 } | 332 } |
335 | 333 |
336 return (node->value < threshold) ? 1 : 0; | 334 return (node->value < threshold) ? 1 : 0; |
337 } | 335 } |
OLD | NEW |