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;
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) + ((f & T1_SIG_SE) != 0) + ((f & T1_SIG_SW) != 0);
110 return (T1_CTXNO_ZC + n);
113 static int t1_init_ctxno_sc(int f) {
117 hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
118 T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
119 1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
120 (T1_SIG_E | T1_SGN_E)) +
121 ((f & (T1_SIG_W | T1_SGN_W)) ==
122 (T1_SIG_W | T1_SGN_W)), 1);
124 vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
125 T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
126 1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
127 (T1_SIG_N | T1_SGN_N)) +
128 ((f & (T1_SIG_S | T1_SGN_S)) ==
129 (T1_SIG_S | T1_SGN_S)), 1);
142 } else if (hc == 1) {
151 return (T1_CTXNO_SC + n);
154 static int t1_init_spb(int f) {
157 hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
158 T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
159 1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
160 (T1_SIG_E | T1_SGN_E)) +
161 ((f & (T1_SIG_W | T1_SGN_W)) ==
162 (T1_SIG_W | T1_SGN_W)), 1);
164 vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
165 T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
166 1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
167 (T1_SIG_N | T1_SGN_N)) +
168 ((f & (T1_SIG_S | T1_SGN_S)) ==
169 (T1_SIG_S | T1_SGN_S)), 1);
174 n = (!(hc > 0 || (!hc && vc > 0)));
179 static void dump_array16(int array[],int size){
182 for (i = 0; i < size; ++i) {
183 printf("0x%04x, ", array[i]);
187 printf("0x%04x\n};\n\n", array[size]);
190 int main(int argc, char **argv)
195 int lut_ctxno_zc[1024];
196 int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
197 int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
198 int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
199 int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
200 (void)argc; (void)argv;
202 printf("/* This file was automatically generated by t1_generate_luts.c */\n\n");
205 for (j = 0; j < 4; ++j) {
206 for (i = 0; i < 256; ++i) {
210 } else if (orient == 1) {
213 lut_ctxno_zc[(orient << 8) | i] = t1_init_ctxno_zc(i, j);
217 printf("static OPJ_BYTE lut_ctxno_zc[1024] = {\n ");
218 for (i = 0; i < 1023; ++i) {
219 printf("%i, ", lut_ctxno_zc[i]);
223 printf("%i\n};\n\n", lut_ctxno_zc[1023]);
226 printf("static OPJ_BYTE lut_ctxno_sc[256] = {\n ");
227 for (i = 0; i < 255; ++i) {
228 printf("0x%x, ", t1_init_ctxno_sc(i << 4));
232 printf("0x%x\n};\n\n", t1_init_ctxno_sc(255 << 4));
235 printf("static OPJ_BYTE lut_spb[256] = {\n ");
236 for (i = 0; i < 255; ++i) {
237 printf("%i, ", t1_init_spb(i << 4));
241 printf("%i\n};\n\n", t1_init_spb(255 << 4));
243 /* FIXME FIXME FIXME */
244 /* fprintf(stdout,"nmsedec luts:\n"); */
245 for (i = 0; i < (1 << T1_NMSEDEC_BITS); ++i) {
246 t = i / pow(2, T1_NMSEDEC_FRACBITS);
251 (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
252 lut_nmsedec_sig0[i] =
254 (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
256 if (i & (1 << (T1_NMSEDEC_BITS - 1))) {
263 (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
264 lut_nmsedec_ref0[i] =
266 (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
269 printf("static OPJ_INT16 lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = {\n ");
270 dump_array16(lut_nmsedec_sig, 1 << T1_NMSEDEC_BITS);
272 printf("static OPJ_INT16 lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {\n ");
273 dump_array16(lut_nmsedec_sig0, 1 << T1_NMSEDEC_BITS);
275 printf("static OPJ_INT16 lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {\n ");
276 dump_array16(lut_nmsedec_ref, 1 << T1_NMSEDEC_BITS);
278 printf("static OPJ_INT16 lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {\n ");
279 dump_array16(lut_nmsedec_ref0, 1 << T1_NMSEDEC_BITS);