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
4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license.
7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
8 * Copyright (c) 2002-2014, Professor Benoit Macq
9 * Copyright (c) 2001-2003, David Janssens
10 * Copyright (c) 2002-2003, Yannick Verschueren
11 * Copyright (c) 2003-2007, Francois-Olivier Devaux
12 * Copyright (c) 2003-2014, Antonin Descampe
13 * Copyright (c) 2005, Herve Drolon, FreeImage Team
14 * Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
15 * Copyright (c) 2012, Carl Hetherington
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
40 #include "opj_includes.h"
42 static int t1_init_ctxno_zc(OPJ_UINT32 f, OPJ_UINT32 orient)
44 int h, v, d, n, t, hv;
46 h = ((f & T1_SIGMA_3) != 0) + ((f & T1_SIGMA_5) != 0);
47 v = ((f & T1_SIGMA_1) != 0) + ((f & T1_SIGMA_7) != 0);
48 d = ((f & T1_SIGMA_0) != 0) + ((f & T1_SIGMA_2) != 0) + ((
49 f & T1_SIGMA_8) != 0) + ((f & T1_SIGMA_6) != 0);
116 return (T1_CTXNO_ZC + n);
119 static int t1_init_ctxno_sc(OPJ_UINT32 f)
124 hc = opj_int_min(((f & (T1_LUT_SIG_E | T1_LUT_SGN_E)) ==
125 T1_LUT_SIG_E) + ((f & (T1_LUT_SIG_W | T1_LUT_SGN_W)) == T1_LUT_SIG_W),
126 1) - opj_int_min(((f & (T1_LUT_SIG_E | T1_LUT_SGN_E)) ==
127 (T1_LUT_SIG_E | T1_LUT_SGN_E)) +
128 ((f & (T1_LUT_SIG_W | T1_LUT_SGN_W)) ==
129 (T1_LUT_SIG_W | T1_LUT_SGN_W)), 1);
131 vc = opj_int_min(((f & (T1_LUT_SIG_N | T1_LUT_SGN_N)) ==
132 T1_LUT_SIG_N) + ((f & (T1_LUT_SIG_S | T1_LUT_SGN_S)) == T1_LUT_SIG_S),
133 1) - opj_int_min(((f & (T1_LUT_SIG_N | T1_LUT_SGN_N)) ==
134 (T1_LUT_SIG_N | T1_LUT_SGN_N)) +
135 ((f & (T1_LUT_SIG_S | T1_LUT_SGN_S)) ==
136 (T1_LUT_SIG_S | T1_LUT_SGN_S)), 1);
150 } else if (hc == 1) {
160 return (T1_CTXNO_SC + n);
163 static int t1_init_spb(OPJ_UINT32 f)
167 hc = opj_int_min(((f & (T1_LUT_SIG_E | T1_LUT_SGN_E)) ==
168 T1_LUT_SIG_E) + ((f & (T1_LUT_SIG_W | T1_LUT_SGN_W)) == T1_LUT_SIG_W),
169 1) - opj_int_min(((f & (T1_LUT_SIG_E | T1_LUT_SGN_E)) ==
170 (T1_LUT_SIG_E | T1_LUT_SGN_E)) +
171 ((f & (T1_LUT_SIG_W | T1_LUT_SGN_W)) ==
172 (T1_LUT_SIG_W | T1_LUT_SGN_W)), 1);
174 vc = opj_int_min(((f & (T1_LUT_SIG_N | T1_LUT_SGN_N)) ==
175 T1_LUT_SIG_N) + ((f & (T1_LUT_SIG_S | T1_LUT_SGN_S)) == T1_LUT_SIG_S),
176 1) - opj_int_min(((f & (T1_LUT_SIG_N | T1_LUT_SGN_N)) ==
177 (T1_LUT_SIG_N | T1_LUT_SGN_N)) +
178 ((f & (T1_LUT_SIG_S | T1_LUT_SGN_S)) ==
179 (T1_LUT_SIG_S | T1_LUT_SGN_S)), 1);
184 n = (!(hc > 0 || (!hc && vc > 0)));
190 static void dump_array16(int array[], int size)
194 for (i = 0; i < size; ++i) {
195 printf("0x%04x,", array[i]);
196 if (!((i + 1) & 0x7)) {
202 printf("0x%04x\n};\n\n", array[size]);
205 int main(int argc, char **argv)
210 int lut_ctxno_zc[2048];
211 int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
212 int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
213 int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
214 int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
218 printf("/* This file was automatically generated by t1_generate_luts.c */\n\n");
221 for (j = 0; j < 4; ++j) {
222 for (i = 0; i < 512; ++i) {
223 OPJ_UINT32 orient = j;
226 } else if (orient == 1) {
229 lut_ctxno_zc[(orient << 9) | i] = t1_init_ctxno_zc(i, j);
233 printf("static const OPJ_BYTE lut_ctxno_zc[2048] = {\n ");
234 for (i = 0; i < 2047; ++i) {
235 printf("%i,", lut_ctxno_zc[i]);
236 if (!((i + 1) & 0x1f)) {
242 printf("%i\n};\n\n", lut_ctxno_zc[2047]);
245 printf("static const OPJ_BYTE lut_ctxno_sc[256] = {\n ");
246 for (i = 0; i < 255; ++i) {
247 printf("0x%x,", t1_init_ctxno_sc(i));
248 if (!((i + 1) & 0xf)) {
254 printf("0x%x\n};\n\n", t1_init_ctxno_sc(255));
257 printf("static const OPJ_BYTE lut_spb[256] = {\n ");
258 for (i = 0; i < 255; ++i) {
259 printf("%i,", t1_init_spb(i));
260 if (!((i + 1) & 0x1f)) {
266 printf("%i\n};\n\n", t1_init_spb(255));
268 /* FIXME FIXME FIXME */
269 /* fprintf(stdout,"nmsedec luts:\n"); */
270 for (i = 0U; i < (1U << T1_NMSEDEC_BITS); ++i) {
271 t = i / pow(2, T1_NMSEDEC_FRACBITS);
276 (int)(floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2,
277 T1_NMSEDEC_FRACBITS) * 8192.0));
278 lut_nmsedec_sig0[i] =
280 (int)(floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2,
281 T1_NMSEDEC_FRACBITS) * 8192.0));
283 if (i & (1 << (T1_NMSEDEC_BITS - 1))) {
290 (int)(floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2,
291 T1_NMSEDEC_FRACBITS) * 8192.0));
292 lut_nmsedec_ref0[i] =
294 (int)(floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2,
295 T1_NMSEDEC_FRACBITS) * 8192.0));
298 printf("static const OPJ_INT16 lut_nmsedec_sig[1U << T1_NMSEDEC_BITS] = {\n ");
299 dump_array16(lut_nmsedec_sig, 1U << T1_NMSEDEC_BITS);
301 printf("static const OPJ_INT16 lut_nmsedec_sig0[1U << T1_NMSEDEC_BITS] = {\n ");
302 dump_array16(lut_nmsedec_sig0, 1U << T1_NMSEDEC_BITS);
304 printf("static const OPJ_INT16 lut_nmsedec_ref[1U << T1_NMSEDEC_BITS] = {\n ");
305 dump_array16(lut_nmsedec_ref, 1U << T1_NMSEDEC_BITS);
307 printf("static const OPJ_INT16 lut_nmsedec_ref0[1U << T1_NMSEDEC_BITS] = {\n ");
308 dump_array16(lut_nmsedec_ref0, 1U << T1_NMSEDEC_BITS);