JPWL version 1.0 by Universita' degli Studi di Perugia
[openjpeg.git] / jpwl / rs.h
1 /*\r
2  * Copyright (c) 2001-2003, David Janssens\r
3  * Copyright (c) 2002-2003, Yannick Verschueren\r
4  * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe\r
5  * Copyright (c) 2005, Herv� Drolon, FreeImage Team\r
6  * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium\r
7  * Copyright (c) 2005-2006, Dept. of Electronic and Information Engineering, Universita' degli Studi di Perugia, Italy\r
8  * All rights reserved.\r
9  *\r
10  * Redistribution and use in source and binary forms, with or without\r
11  * modification, are permitted provided that the following conditions\r
12  * are met:\r
13  * 1. Redistributions of source code must retain the above copyright\r
14  *    notice, this list of conditions and the following disclaimer.\r
15  * 2. Redistributions in binary form must reproduce the above copyright\r
16  *    notice, this list of conditions and the following disclaimer in the\r
17  *    documentation and/or other materials provided with the distribution.\r
18  *\r
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'\r
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
29  * POSSIBILITY OF SUCH DAMAGE.\r
30  */\r
31 \r
32 #ifdef USE_JPWL\r
33 \r
34 /**\r
35 @file rs.h\r
36 @brief Functions used to compute Reed-Solomon parity and check of byte arrays\r
37 \r
38 */\r
39 \r
40 #ifndef __RS_HEADER__\r
41 #define __RS_HEADER__\r
42 \r
43 /** Global definitions for Reed-Solomon encoder/decoder\r
44  * Phil Karn KA9Q, September 1996\r
45  *\r
46  * The parameters MM and KK specify the Reed-Solomon code parameters.\r
47  *\r
48  * Set MM to be the size of each code symbol in bits. The Reed-Solomon\r
49  * block size will then be NN = 2**M - 1 symbols. Supported values are\r
50  * defined in rs.c.\r
51  *\r
52  * Set KK to be the number of data symbols in each block, which must be\r
53  * less than the block size. The code will then be able to correct up\r
54  * to NN-KK erasures or (NN-KK)/2 errors, or combinations thereof with\r
55  * each error counting as two erasures.\r
56  */\r
57 #define MM  8           /* RS code over GF(2**MM) - change to suit */\r
58 static int      KK;\r
59 \r
60 /* Original code */\r
61 /*#define KK  239*/             /* KK = number of information symbols */\r
62 \r
63 #define NN ((1 << MM) - 1)\r
64 \r
65 #if (MM <= 8)\r
66 typedef unsigned char dtype;\r
67 #else\r
68 typedef unsigned int dtype;\r
69 #endif\r
70 \r
71 /** Initialization function */\r
72 void init_rs(int);\r
73 \r
74 /** These two functions *must* be called in this order (e.g.,\r
75  * by init_rs()) before any encoding/decoding\r
76  */\r
77 void generate_gf(void); /* Generate Galois Field */\r
78 void gen_poly(void);    /* Generate generator polynomial */\r
79 \r
80 /** Reed-Solomon encoding\r
81  * data[] is the input block, parity symbols are placed in bb[]\r
82  * bb[] may lie past the end of the data, e.g., for (255,223):\r
83  *      encode_rs(&data[0],&data[223]);\r
84  */\r
85 int encode_rs(dtype data[], dtype bb[]);\r
86 \r
87 /** Reed-Solomon erasures-and-errors decoding\r
88  * The received block goes into data[], and a list of zero-origin\r
89  * erasure positions, if any, goes in eras_pos[] with a count in no_eras.\r
90  *\r
91  * The decoder corrects the symbols in place, if possible and returns\r
92  * the number of corrected symbols. If the codeword is illegal or\r
93  * uncorrectible, the data array is unchanged and -1 is returned\r
94  */\r
95 int eras_dec_rs(dtype data[], int eras_pos[], int no_eras);\r
96 \r
97 \r
98 #endif /* __CRC32_HEADER__ */\r
99 \r
100 \r
101 #endif /* USE_JPWL */