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(int f, int orient) {
42 int h, v, d, n, t, hv;
43 h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0);
44 v = ((f & T1_SIG_N) != 0) + ((f & T1_SIG_S) != 0);
45 d = ((f & T1_SIG_NW) != 0) + ((f & T1_SIG_NE) != 0) + ((f & T1_SIG_SE) != 0) + ((f & T1_SIG_SW) != 0);
112 return (T1_CTXNO_ZC + n);
115 static int t1_init_ctxno_sc(int f) {
119 hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
120 T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
121 1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
122 (T1_SIG_E | T1_SGN_E)) +
123 ((f & (T1_SIG_W | T1_SGN_W)) ==
124 (T1_SIG_W | T1_SGN_W)), 1);
126 vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
127 T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
128 1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
129 (T1_SIG_N | T1_SGN_N)) +
130 ((f & (T1_SIG_S | T1_SGN_S)) ==
131 (T1_SIG_S | T1_SGN_S)), 1);
144 } else if (hc == 1) {
153 return (T1_CTXNO_SC + n);
156 static int t1_init_spb(int f) {
159 hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
160 T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
161 1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
162 (T1_SIG_E | T1_SGN_E)) +
163 ((f & (T1_SIG_W | T1_SGN_W)) ==
164 (T1_SIG_W | T1_SGN_W)), 1);
166 vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
167 T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
168 1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
169 (T1_SIG_N | T1_SGN_N)) +
170 ((f & (T1_SIG_S | T1_SGN_S)) ==
171 (T1_SIG_S | T1_SGN_S)), 1);
176 n = (!(hc > 0 || (!hc && vc > 0)));
181 static void dump_array16(int array[],int size){
184 for (i = 0; i < size; ++i) {
185 printf("0x%04x, ", array[i]);
189 printf("0x%04x\n};\n\n", array[size]);
192 int main(int argc, char **argv)
197 int lut_ctxno_zc[1024];
198 int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
199 int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
200 int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
201 int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
202 (void)argc; (void)argv;
204 printf("/* This file was automatically generated by t1_generate_luts.c */\n\n");
207 for (j = 0; j < 4; ++j) {
208 for (i = 0; i < 256; ++i) {
212 } else if (orient == 1) {
215 lut_ctxno_zc[(orient << 8) | i] = t1_init_ctxno_zc(i, j);
219 printf("static OPJ_BYTE lut_ctxno_zc[1024] = {\n ");
220 for (i = 0; i < 1023; ++i) {
221 printf("%i, ", lut_ctxno_zc[i]);
225 printf("%i\n};\n\n", lut_ctxno_zc[1023]);
228 printf("static OPJ_BYTE lut_ctxno_sc[256] = {\n ");
229 for (i = 0; i < 255; ++i) {
230 printf("0x%x, ", t1_init_ctxno_sc(i << 4));
234 printf("0x%x\n};\n\n", t1_init_ctxno_sc(255 << 4));
237 printf("static OPJ_BYTE lut_spb[256] = {\n ");
238 for (i = 0; i < 255; ++i) {
239 printf("%i, ", t1_init_spb(i << 4));
243 printf("%i\n};\n\n", t1_init_spb(255 << 4));
245 /* FIXME FIXME FIXME */
246 /* fprintf(stdout,"nmsedec luts:\n"); */
247 for (i = 0; i < (1 << T1_NMSEDEC_BITS); ++i) {
248 t = i / pow(2, T1_NMSEDEC_FRACBITS);
253 (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
254 lut_nmsedec_sig0[i] =
256 (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
258 if (i & (1 << (T1_NMSEDEC_BITS - 1))) {
265 (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
266 lut_nmsedec_ref0[i] =
268 (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
271 printf("static OPJ_INT16 lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = {\n ");
272 dump_array16(lut_nmsedec_sig, 1 << T1_NMSEDEC_BITS);
274 printf("static OPJ_INT16 lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {\n ");
275 dump_array16(lut_nmsedec_sig0, 1 << T1_NMSEDEC_BITS);
277 printf("static OPJ_INT16 lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {\n ");
278 dump_array16(lut_nmsedec_ref, 1 << T1_NMSEDEC_BITS);
280 printf("static OPJ_INT16 lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {\n ");
281 dump_array16(lut_nmsedec_ref0, 1 << T1_NMSEDEC_BITS);