OLD | NEW |
(Empty) | |
| 1 diff --git a/third_party/libopenjpeg20/dwt.c b/third_party/libopenjpeg20/dwt.c |
| 2 index 4ad99ed..975a97e 100644 |
| 3 --- a/third_party/libopenjpeg20/dwt.c |
| 4 +++ b/third_party/libopenjpeg20/dwt.c |
| 5 @@ -46,14 +46,12 @@ |
| 6 /** @defgroup DWT DWT - Implementation of a discrete wavelet transform */ |
| 7 /*@{*/ |
| 8 |
| 9 -#define OPJ_WS(i) v->mem[(i)*2] |
| 10 -#define OPJ_WD(i) v->mem[(1+(i)*2)] |
| 11 - |
| 12 /** @name Local data structures */ |
| 13 /*@{*/ |
| 14 |
| 15 typedef struct dwt_local { |
| 16 OPJ_INT32* mem; |
| 17 + OPJ_SIZE_T mem_count; |
| 18 OPJ_INT32 dn; |
| 19 OPJ_INT32 sn; |
| 20 OPJ_INT32 cas; |
| 21 @@ -107,16 +105,16 @@ static void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *
a, OPJ_INT32 x); |
| 22 /** |
| 23 Forward 5-3 wavelet transform in 1-D |
| 24 */ |
| 25 -static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT3
2 cas); |
| 26 +static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_SIZE_T a_count, OPJ_INT32 dn, OP
J_INT32 sn, OPJ_INT32 cas); |
| 27 /** |
| 28 Inverse 5-3 wavelet transform in 1-D |
| 29 */ |
| 30 static void opj_dwt_decode_1(opj_dwt_t *v); |
| 31 -static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT
32 cas); |
| 32 +static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_SIZE_T a_count, OPJ_INT32 dn, O
PJ_INT32 sn, OPJ_INT32 cas); |
| 33 /** |
| 34 Forward 9-7 wavelet transform in 1-D |
| 35 */ |
| 36 -static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ
_INT32 cas); |
| 37 +static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_SIZE_T a_count, OPJ_INT32 d
n, OPJ_INT32 sn, OPJ_INT32 cas); |
| 38 /** |
| 39 Explicit calculation of the Quantization Stepsizes |
| 40 */ |
| 41 @@ -124,10 +122,10 @@ static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OP
J_INT32 numbps, opj_st |
| 42 /** |
| 43 Inverse wavelet transform in 2-D. |
| 44 */ |
| 45 -static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 i, DW
T1DFN fn); |
| 46 +static OPJ_BOOL opj_dwt_decode_tile(const opj_tcd_tilecomp_t* tilec, OPJ_UINT32
i, DWT1DFN fn); |
| 47 |
| 48 -static OPJ_BOOL opj_dwt_encode_procedure( opj_tcd_tilecomp_t * tilec, |
| 49 -
void (*p_function)(OPJ_INT32 *, OPJ_INT32,OPJ_INT32,OPJ_INT32) ); |
| 50 +static OPJ_BOOL opj_dwt_encode_procedure(const opj_tcd_tilecomp_t * tilec, |
| 51 +
void(*p_function)(OPJ_INT32 *, OPJ_SIZE_T, OPJ_INT32, OPJ_INT32, OPJ_INT32))
; |
| 52 |
| 53 static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_
UINT32 i); |
| 54 |
| 55 @@ -156,13 +154,20 @@ static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t*
w, OPJ_INT32 k, OPJ_IN |
| 56 |
| 57 /*@}*/ |
| 58 |
| 59 -#define OPJ_S(i) a[(i)*2] |
| 60 -#define OPJ_D(i) a[(1+(i)*2)] |
| 61 -#define OPJ_S_(i) ((i)<0?OPJ_S(0):((i)>=sn?OPJ_S(sn-1):OPJ_S(i))) |
| 62 -#define OPJ_D_(i) ((i)<0?OPJ_D(0):((i)>=dn?OPJ_D(dn-1):OPJ_D(i))) |
| 63 -/* new */ |
| 64 -#define OPJ_SS_(i) ((i)<0?OPJ_S(0):((i)>=dn?OPJ_S(dn-1):OPJ_S(i))) |
| 65 -#define OPJ_DD_(i) ((i)<0?OPJ_D(0):((i)>=sn?OPJ_D(sn-1):OPJ_D(i))) |
| 66 +#define IDX_S(i) (i)*2 |
| 67 +#define IDX_D(i) 1 + (i)* 2 |
| 68 +#define UNDERFLOW_SN(i) ((i) >= sn&&sn>0) |
| 69 +#define UNDERFLOW_DN(i) ((i) >= dn&&dn>0) |
| 70 +#define OVERFLOW_S(i) (IDX_S(i) >= a_count) |
| 71 +#define OVERFLOW_D(i) (IDX_D(i) >= a_count) |
| 72 + |
| 73 +#define OPJ_S(i) a[IDX_S(i)] |
| 74 +#define OPJ_D(i) a[IDX_D(i)] |
| 75 +#define OPJ_S_(i) ((i)<0 ? OPJ_S(0) : (UNDERFLOW_SN(i) ? OPJ_S(sn - 1) : OVERFL
OW_S(i) ? OPJ_S(i - 1) : OPJ_S(i))) |
| 76 +#define OPJ_D_(i) ((i)<0 ? OPJ_D(0) : (UNDERFLOW_DN(i) ? OPJ_D(dn - 1) : OVERFL
OW_D(i) ? OPJ_D(i - 1) : OPJ_D(i))) |
| 77 +/* new */ |
| 78 +#define OPJ_SS_(i) ((i)<0 ? OPJ_S(0) : (UNDERFLOW_DN(i) ? OPJ_S(dn - 1) : OVERF
LOW_S(i) ? OPJ_S(i - 1) : OPJ_S(i))) |
| 79 +#define OPJ_DD_(i) ((i)<0 ? OPJ_D(0) : (UNDERFLOW_SN(i) ? OPJ_D(sn - 1) : OVERF
LOW_D(i) ? OPJ_D(i - 1) : OPJ_D(i))) |
| 80 |
| 81 /* <summary> */ |
| 82 /* This table contains the norms of the 5-3 wavelets for different bands. */ |
| 83 @@ -283,7 +288,7 @@ static void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a,
OPJ_INT32 x) { |
| 84 /* <summary> */ |
| 85 /* Forward 5-3 wavelet transform in 1-D. */ |
| 86 /* </summary> */ |
| 87 -static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT3
2 cas) { |
| 88 +static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_SIZE_T a_count, OPJ_INT32 dn, OP
J_INT32 sn, OPJ_INT32 cas) { |
| 89 OPJ_INT32 i; |
| 90 |
| 91 if (!cas) { |
| 92 @@ -304,7 +309,7 @@ static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ
_INT32 sn, OPJ_INT32 |
| 93 /* <summary> */ |
| 94 /* Inverse 5-3 wavelet transform in 1-D. */ |
| 95 /* </summary> */ |
| 96 -static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT
32 cas) { |
| 97 +static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_SIZE_T a_count, OPJ_INT32 dn, O
PJ_INT32 sn, OPJ_INT32 cas) { |
| 98 OPJ_INT32 i; |
| 99 |
| 100 if (!cas) { |
| 101 @@ -326,13 +331,13 @@ static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn,
OPJ_INT32 sn, OPJ_INT3 |
| 102 /* Inverse 5-3 wavelet transform in 1-D. */ |
| 103 /* </summary> */ |
| 104 static void opj_dwt_decode_1(opj_dwt_t *v) { |
| 105 - opj_dwt_decode_1_(v->mem, v->dn, v->sn, v->cas); |
| 106 + opj_dwt_decode_1_(v->mem, v->mem_count, v->dn, v->sn, v->cas); |
| 107 } |
| 108 |
| 109 /* <summary> */ |
| 110 /* Forward 9-7 wavelet transform in 1-D. */ |
| 111 /* </summary> */ |
| 112 -static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ
_INT32 cas) { |
| 113 +static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_SIZE_T a_count, OPJ_INT32 d
n, OPJ_INT32 sn, OPJ_INT32 cas) { |
| 114 OPJ_INT32 i; |
| 115 if (!cas) { |
| 116 if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ |
| 117 @@ -385,7 +390,7 @@ static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_
INT32 numbps, opj_st |
| 118 /* <summary> */ |
| 119 /* Forward 5-3 wavelet transform in 2-D. */ |
| 120 /* </summary> */ |
| 121 -static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void
(*p_function)(OPJ_INT32 *, OPJ_INT32,OPJ_INT32,OPJ_INT32) ) |
| 122 +static INLINE OPJ_BOOL opj_dwt_encode_procedure(const opj_tcd_tilecomp_t * tile
c, void(*p_function)(OPJ_INT32 *, OPJ_SIZE_T, OPJ_INT32, OPJ_INT32, OPJ_INT32)) |
| 123 { |
| 124 OPJ_INT32 i, j, k; |
| 125 OPJ_INT32 *a = 00; |
| 126 @@ -395,7 +400,8 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tile
comp_t * tilec,void |
| 127 |
| 128 OPJ_INT32 rw; /* width of the resolution level compute
d */ |
| 129 OPJ_INT32 rh; /* height of the resolution level comput
ed */ |
| 130 - OPJ_UINT32 l_data_size; |
| 131 + OPJ_SIZE_T l_data_count; |
| 132 + OPJ_SIZE_T l_data_size; |
| 133 |
| 134 opj_tcd_resolution_t * l_cur_res = 0; |
| 135 opj_tcd_resolution_t * l_last_res = 0; |
| 136 @@ -407,8 +413,9 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tile
comp_t * tilec,void |
| 137 l_cur_res = tilec->resolutions + l; |
| 138 l_last_res = l_cur_res - 1; |
| 139 |
| 140 - l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresol
utions) * (OPJ_UINT32)sizeof(OPJ_INT32); |
| 141 - bj = (OPJ_INT32*)opj_malloc((size_t)l_data_size); |
| 142 + l_data_count = opj_dwt_max_resolution(tilec->resolutions, tilec->numreso
lutions) * (OPJ_UINT32)sizeof(OPJ_INT32); |
| 143 + l_data_size = l_data_count * (OPJ_UINT32)sizeof(OPJ_INT32); |
| 144 + bj = (OPJ_INT32*)opj_malloc(l_data_size); |
| 145 if (! bj) { |
| 146 return OPJ_FALSE; |
| 147 } |
| 148 @@ -437,7 +444,7 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tile
comp_t * tilec,void |
| 149 bj[k] = aj[k*w]; |
| 150 } |
| 151 |
| 152 - (*p_function) (bj, dn, sn, cas_col); |
| 153 + (*p_function) (bj, l_data_count, dn, sn, cas_col); |
| 154 |
| 155 opj_dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col); |
| 156 } |
| 157 @@ -448,7 +455,7 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tile
comp_t * tilec,void |
| 158 for (j = 0; j < rh; j++) { |
| 159 aj = a + j * w; |
| 160 for (k = 0; k < rw; k++) bj[k] = aj[k]; |
| 161 - (*p_function) (bj, dn, sn, cas_row); |
| 162 + (*p_function) (bj, l_data_count, dn, sn, cas_row); |
| 163 opj_dwt_deinterleave_h(bj, aj, dn, sn, cas_row); |
| 164 } |
| 165 |
| 166 @@ -557,7 +564,7 @@ static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_
t* restrict r, OPJ_U |
| 167 /* <summary> */ |
| 168 /* Inverse wavelet transform in 2-D. */ |
| 169 /* </summary> */ |
| 170 -static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numre
s, DWT1DFN dwt_1D) { |
| 171 +static OPJ_BOOL opj_dwt_decode_tile(const opj_tcd_tilecomp_t* tilec, OPJ_UINT32
numres, DWT1DFN dwt_1D) { |
| 172 opj_dwt_t h; |
| 173 opj_dwt_t v; |
| 174 |
| 175 @@ -568,13 +575,14 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* ti
lec, OPJ_UINT32 numres |
| 176 |
| 177 OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0); |
| 178 |
| 179 - h.mem = (OPJ_INT32*) |
| 180 - opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32
)); |
| 181 + h.mem_count = opj_dwt_max_resolution(tr, numres); |
| 182 + h.mem = (OPJ_INT32*)opj_aligned_malloc(h.mem_count * sizeof(OPJ_INT32)); |
| 183 if (! h.mem){ |
| 184 /* FIXME event manager error callback */ |
| 185 return OPJ_FALSE; |
| 186 } |
| 187 |
| 188 + v.mem_count = h.mem_count; |
| 189 v.mem = h.mem; |
| 190 |
| 191 while( --numres) { |
OLD | NEW |