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 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
39 #include "opj_includes.h"
41 static int t1_init_ctxno_zc(unsigned int f, unsigned int orient)
43 int h, v, d, n, t, hv;
44 h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0);
45 v = ((f & T1_SIG_N) != 0) + ((f & T1_SIG_S) != 0);
46 d = ((f & T1_SIG_NW) != 0) + ((f & T1_SIG_NE) != 0) + ((
47 f & T1_SIG_SE) != 0) + ((f & T1_SIG_SW) != 0);
101 } else if (hv == 1) {
118 return (T1_CTXNO_ZC + n);
121 static int t1_init_ctxno_sc(unsigned int f)
126 hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
127 T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
128 1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
129 (T1_SIG_E | T1_SGN_E)) +
130 ((f & (T1_SIG_W | T1_SGN_W)) ==
131 (T1_SIG_W | T1_SGN_W)), 1);
133 vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
134 T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
135 1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
136 (T1_SIG_N | T1_SGN_N)) +
137 ((f & (T1_SIG_S | T1_SGN_S)) ==
138 (T1_SIG_S | T1_SGN_S)), 1);
152 } else if (hc == 1) {
162 return (T1_CTXNO_SC + n);
165 static int t1_init_spb(unsigned int f)
169 hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
170 T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
171 1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
172 (T1_SIG_E | T1_SGN_E)) +
173 ((f & (T1_SIG_W | T1_SGN_W)) ==
174 (T1_SIG_W | T1_SGN_W)), 1);
176 vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
177 T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
178 1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
179 (T1_SIG_N | T1_SGN_N)) +
180 ((f & (T1_SIG_S | T1_SGN_S)) ==
181 (T1_SIG_S | T1_SGN_S)), 1);
186 n = (!(hc > 0 || (!hc && vc > 0)));
192 static void dump_array16(int array[], int size)
196 for (i = 0; i < size; ++i) {
197 printf("0x%04x, ", array[i]);
198 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[1024];
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 = 0U; j < 4U; ++j) {
222 for (i = 0U; i < 256U; ++i) {
223 unsigned int orient = j;
226 } else if (orient == 1U) {
229 lut_ctxno_zc[(orient << 8) | i] = t1_init_ctxno_zc(i, j);
233 printf("static const OPJ_BYTE lut_ctxno_zc[1024] = {\n ");
234 for (i = 0U; i < 1023U; ++i) {
235 printf("%i, ", lut_ctxno_zc[i]);
236 if (!((i + 1U) & 0x1fU)) {
240 printf("%i\n};\n\n", lut_ctxno_zc[1023]);
243 printf("static const OPJ_BYTE lut_ctxno_sc[256] = {\n ");
244 for (i = 0U; i < 255U; ++i) {
245 printf("0x%x, ", t1_init_ctxno_sc(i << 4));
246 if (!((i + 1U) & 0xfU)) {
250 printf("0x%x\n};\n\n", t1_init_ctxno_sc(255U << 4));
253 printf("static const OPJ_BYTE lut_spb[256] = {\n ");
254 for (i = 0U; i < 255U; ++i) {
255 printf("%i, ", t1_init_spb(i << 4));
256 if (!((i + 1U) & 0x1fU)) {
260 printf("%i\n};\n\n", t1_init_spb(255U << 4));
262 /* FIXME FIXME FIXME */
263 /* fprintf(stdout,"nmsedec luts:\n"); */
264 for (i = 0U; i < (1U << T1_NMSEDEC_BITS); ++i) {
265 t = i / pow(2, T1_NMSEDEC_FRACBITS);
270 (int)(floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2,
271 T1_NMSEDEC_FRACBITS) * 8192.0));
272 lut_nmsedec_sig0[i] =
274 (int)(floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2,
275 T1_NMSEDEC_FRACBITS) * 8192.0));
277 if (i & (1 << (T1_NMSEDEC_BITS - 1))) {
284 (int)(floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2,
285 T1_NMSEDEC_FRACBITS) * 8192.0));
286 lut_nmsedec_ref0[i] =
288 (int)(floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2,
289 T1_NMSEDEC_FRACBITS) * 8192.0));
292 printf("static const OPJ_INT16 lut_nmsedec_sig[1U << T1_NMSEDEC_BITS] = {\n ");
293 dump_array16(lut_nmsedec_sig, 1U << T1_NMSEDEC_BITS);
295 printf("static const OPJ_INT16 lut_nmsedec_sig0[1U << T1_NMSEDEC_BITS] = {\n ");
296 dump_array16(lut_nmsedec_sig0, 1U << T1_NMSEDEC_BITS);
298 printf("static const OPJ_INT16 lut_nmsedec_ref[1U << T1_NMSEDEC_BITS] = {\n ");
299 dump_array16(lut_nmsedec_ref, 1U << T1_NMSEDEC_BITS);
301 printf("static const OPJ_INT16 lut_nmsedec_ref0[1U << T1_NMSEDEC_BITS] = {\n ");
302 dump_array16(lut_nmsedec_ref0, 1U << T1_NMSEDEC_BITS);