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);
113 return (T1_CTXNO_ZC + n);
116 static int t1_init_ctxno_sc(int f) {
120 hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
121 T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
122 1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
123 (T1_SIG_E | T1_SGN_E)) +
124 ((f & (T1_SIG_W | T1_SGN_W)) ==
125 (T1_SIG_W | T1_SGN_W)), 1);
127 vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
128 T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
129 1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
130 (T1_SIG_N | T1_SGN_N)) +
131 ((f & (T1_SIG_S | T1_SGN_S)) ==
132 (T1_SIG_S | T1_SGN_S)), 1);
145 } else if (hc == 1) {
154 return (T1_CTXNO_SC + n);
157 static int t1_init_spb(int f) {
160 hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
161 T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
162 1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
163 (T1_SIG_E | T1_SGN_E)) +
164 ((f & (T1_SIG_W | T1_SGN_W)) ==
165 (T1_SIG_W | T1_SGN_W)), 1);
167 vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
168 T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
169 1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
170 (T1_SIG_N | T1_SGN_N)) +
171 ((f & (T1_SIG_S | T1_SGN_S)) ==
172 (T1_SIG_S | T1_SGN_S)), 1);
177 n = (!(hc > 0 || (!hc && vc > 0)));
182 static void dump_array16(int array[],int size){
185 for (i = 0; i < size; ++i) {
186 printf("0x%04x, ", array[i]);
190 printf("0x%04x\n};\n\n", array[size]);
193 int main(int argc, char **argv)
198 int lut_ctxno_zc[1024];
199 int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
200 int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
201 int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
202 int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
203 (void)argc; (void)argv;
205 printf("/* This file was automatically generated by t1_generate_luts.c */\n\n");
208 for (j = 0; j < 4; ++j) {
209 for (i = 0; i < 256; ++i) {
213 } else if (orient == 1) {
216 lut_ctxno_zc[(orient << 8) | i] = t1_init_ctxno_zc(i, j);
220 printf("static const OPJ_BYTE lut_ctxno_zc[1024] = {\n ");
221 for (i = 0; i < 1023; ++i) {
222 printf("%i, ", lut_ctxno_zc[i]);
226 printf("%i\n};\n\n", lut_ctxno_zc[1023]);
229 printf("static const OPJ_BYTE lut_ctxno_sc[256] = {\n ");
230 for (i = 0; i < 255; ++i) {
231 printf("0x%x, ", t1_init_ctxno_sc(i << 4));
235 printf("0x%x\n};\n\n", t1_init_ctxno_sc(255 << 4));
238 printf("static const OPJ_BYTE lut_spb[256] = {\n ");
239 for (i = 0; i < 255; ++i) {
240 printf("%i, ", t1_init_spb(i << 4));
244 printf("%i\n};\n\n", t1_init_spb(255 << 4));
246 /* FIXME FIXME FIXME */
247 /* fprintf(stdout,"nmsedec luts:\n"); */
248 for (i = 0; i < (1 << T1_NMSEDEC_BITS); ++i) {
249 t = i / pow(2, T1_NMSEDEC_FRACBITS);
254 (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
255 lut_nmsedec_sig0[i] =
257 (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
259 if (i & (1 << (T1_NMSEDEC_BITS - 1))) {
266 (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
267 lut_nmsedec_ref0[i] =
269 (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
272 printf("static const OPJ_INT16 lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = {\n ");
273 dump_array16(lut_nmsedec_sig, 1 << T1_NMSEDEC_BITS);
275 printf("static const OPJ_INT16 lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {\n ");
276 dump_array16(lut_nmsedec_sig0, 1 << T1_NMSEDEC_BITS);
278 printf("static const OPJ_INT16 lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {\n ");
279 dump_array16(lut_nmsedec_ref, 1 << T1_NMSEDEC_BITS);
281 printf("static const OPJ_INT16 lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {\n ");
282 dump_array16(lut_nmsedec_ref0, 1 << T1_NMSEDEC_BITS);