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
10 * Redistribution and use in source and binary forms, with or without
\r
11 * modification, are permitted provided that the following conditions
\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
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
36 @brief Functions used to compute Reed-Solomon parity and check of byte arrays
\r
40 #ifndef __RS_HEADER__
\r
41 #define __RS_HEADER__
\r
43 /** Global definitions for Reed-Solomon encoder/decoder
\r
44 * Phil Karn KA9Q, September 1996
\r
46 * The parameters MM and KK specify the Reed-Solomon code parameters.
\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
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
57 #define MM 8 /* RS code over GF(2**MM) - change to suit */
\r
61 /*#define KK 239*/ /* KK = number of information symbols */
\r
63 #define NN ((1 << MM) - 1)
\r
66 typedef unsigned char dtype;
\r
68 typedef unsigned int dtype;
\r
71 /** Initialization function */
\r
74 /** These two functions *must* be called in this order (e.g.,
\r
75 * by init_rs()) before any encoding/decoding
\r
77 void generate_gf(void); /* Generate Galois Field */
\r
78 void gen_poly(void); /* Generate generator polynomial */
\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
85 int encode_rs(dtype data[], dtype bb[]);
\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
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
95 int eras_dec_rs(dtype data[], int eras_pos[], int no_eras);
\r
98 #endif /* __CRC32_HEADER__ */
\r
101 #endif /* USE_JPWL */